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

This commit is contained in:
2024-11-05 11:13:51 +08:00
parent 2cb5e97e04
commit f0e2dafc8d
+11 -9
View File
@@ -83,18 +83,20 @@ def load_data(filepath):
- np.array: 特征数据。
- np.array: 标签数据。
"""
# 使用 pandas 加载数据
data = pd.read_csv(filepath, header=None, na_values='?')
# 使用 numpy.genfromtxt 加载数据,指定缺失值
data = np.genfromtxt(filepath, delimiter=',', dtype=None, encoding=None, invalid_raise=False, filling_values=np.nan, autostrip=True)
# 将数据中的缺失值用均值填充(或可以选择其他策略)
data.fillna(data.mean(), inplace=True)
# 将数据拆分为特征和标签
X = data[:, :-1].astype(float) # 假设最后一列为标签,并转换为浮点数
y = data[:, -1] # 最后一列为标签
# 提取特征和标签
X = data.iloc[:, :-1].values # 假设最后一列为标签
y = data.iloc[:, -1].values # 最后一列为标签
# 删除任何缺失值行(NaN)
valid_indices = ~np.isnan(X).any(axis=1) & ~np.isnan(y)
X = X[valid_indices]
y = y[valid_indices]
# 确保 y 是二进制的,1表示死亡,0表示存活
y = np.where(y == 1, 1, 0) # 处理标签,确保其为0或1
# 处理 y,确保 y 是二进制的,1表示死亡,0表示存活
y = np.where(y == 1, 1, 0) # 假设标签中1和其他值需要统一成0或1
return X, y