更新 function.py
Gitea Actions Experiment Test / Experiment-Actions (push) Successful in 12s

This commit is contained in:
2024-11-05 11:16:27 +08:00
parent c17c77c8be
commit 8346632a7b
+11 -7
View File
@@ -82,21 +82,25 @@ def load_data(filepath):
- np.array: 特征数据。
- np.array: 标签数据。
"""
# 使用 numpy.genfromtxt 加载数据,指定缺失值
# 加载数据,使用适当的分隔符和设置
data = np.genfromtxt(filepath, delimiter=',', dtype=None, encoding=None, invalid_raise=False, filling_values=np.nan, autostrip=True)
# 将数据拆分为特征和标签
X = data[:, :-1].astype(float) # 假设最后一列为标签,并转换为浮点数
print("Loaded data shape:", data.shape) # 打印数据的形状
# 检查是否成功加载了二维数据
if data.ndim == 1:
raise ValueError("Loaded data is one-dimensional, please check the file format.")
X = data[:, :-1].astype(float) # 假设最后一列为标签
y = data[:, -1] # 最后一列为标签
# 删除任何缺失值行(NaN)
# 检查有效索引
valid_indices = ~np.isnan(X).any(axis=1) & ~np.isnan(y)
X = X[valid_indices]
y = y[valid_indices]
# 处理 y,确保 y 是二进制的,1表示死亡,0表示存活
y = np.where(y == 1, 1, 0) # 假设标签中1和其他值需要统一成0或1
return X, y
y = np.where(y == 1, 1, 0)
return X, y
if __name__ == "__main__":