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

This commit is contained in:
2024-11-21 16:58:32 +08:00
parent 6b6aa8df7b
commit ab0648b00b
+6 -2
View File
@@ -112,11 +112,15 @@ def load_data(filepath):
X[X == '?'] = np.nan
# 将特征数据转换为浮点数
X = X.astype(float)
try:
X = X.astype(float)
except ValueError as e:
print(f"转换特征数据时出错: {e}")
print("特征数据内容:", X)
# 处理缺失值:可以选择填充或删除
# 这里选择用列的均值填充缺失值
col_mean = np.nanmean(X, axis=0) # 计算每列的均值
col_mean = np.nanmean(X.astype(float), axis=0) # 计算每列的均值
inds = np.where(np.isnan(X)) # 找到缺失值的索引
X[inds] = np.take(col_mean, inds[1]) # 用均值填充缺失值