更新 function.py
Gitea Actions Experiment Test / Experiment-Actions (push) Has been cancelled

This commit is contained in:
2024-10-31 15:59:02 +08:00
parent e609a58412
commit 982b068ffe
+5 -4
View File
@@ -54,15 +54,16 @@ def load_data(filepath):
- np.array: 特征数据。
- np.array: 标签数据。
"""
data = np.loadtxt(filepath, delimiter=",", dtype=float)
data = np.genfromtxt(filepath, delimiter=" ", dtype=float, missing_values="?", filling_values=np.nan)
# 检查缺失值并使用列均值进行填充
# 使用列均值填充缺失值
col_means = np.nanmean(data, axis=0)
indices = np.where(np.isnan(data))
data[indices] = np.take(col_means, indices[1])
X = data[:, :-1]
y = data[:, -1]
X = data[:, :-1] # 特征
y = data[:, -1] # 标签
return X, y
if __name__ == "__main__":