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

This commit is contained in:
2024-11-05 15:10:04 +08:00
parent 5f0edf487a
commit fba273d85b
+6 -5
View File
@@ -91,22 +91,23 @@ def load_data(filepath):
- directory (str): 数据文件路径。
Returns:
- Tuple[np.array, np.array]: 特征数据和标签数据。
- np.array: 特征数据。
- np.array: 标签数据。
"""
data = []
with open(filepath, 'r') as f:
for line in f:
row = []
values = line.strip().split()
if '?' in values:
continue # Ignore lines with missing data
for value in values:
row.append(float(value))
try:
row.append(float(value))
except ValueError:
row.append(-1)
data.append(row)
np_data = np.array(data)
X = np_data[:, :-1]
y = np_data[:, -1]
y = np.array([0 if label == 1 else (1 if label == 2 else -1) for label in y])
return X, y
if __name__ == "__main__":