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

This commit is contained in:
Wyy
2024-11-02 20:50:07 +08:00
parent e062dd40bd
commit a12eaee527
+4 -12
View File
@@ -64,18 +64,10 @@ def load_data(filepath):
- X (np.array): 特征数据。 - X (np.array): 特征数据。
- y (np.array): 标签数据。 - y (np.array): 标签数据。
""" """
# 使用np.genfromtxt加载数据,并且忽略文件中不能转换为float的行 data = np.genfromtxt(filepath, delimiter=',', dtype=float, filling_values=0)
with open(filepath, 'r') as file: # 将问号 '?' 替换为 NaN,并将 NaN 替换为 0
lines = file.readlines() data = np.where(data == '?', np.nan, data)
data = np.where(np.isnan(data), 0, data)
data = []
for line in lines:
split_line = line.strip().split()
# 将非数值数据转换为0
split_line = [float(x) if x else 0 for x in split_line]
data.append(split_line)
data = np.array(data)
X = data[:, :-1] X = data[:, :-1]
y = data[:, -1] y = data[:, -1]
return X, y return X, y