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

This commit is contained in:
2024-11-21 17:17:36 +08:00
parent 044995ac45
commit 3a01cb9965
+5 -2
View File
@@ -89,12 +89,15 @@ def load_data(filepath):
- np.array: 特征数据。
- np.array: 标签数据。
"""
data = np.loadtxt(filepath, delimiter=',', dtype=str)
data = np.loadtxt(filepath, delimiter=',', dtype=str, comments=None)
# 检查数据的维度
if data.ndim == 1:
data = data.reshape(1, -1) # 如果数据是一维的,重塑为二维
# 清洗数据,去除无法转换的值
data = np.where(data == '?', '0', data) # 将问号替换为0或其他合适的值
X = data[:, :-1].astype(float) # 特征数据
y = data[:, -1] # 标签数据