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

This commit is contained in:
2024-11-21 16:56:08 +08:00
parent 201132f0c7
commit 8491852abb
+10 -2
View File
@@ -90,8 +90,16 @@ def load_data(filepath):
- np.array: 标签数据。 - np.array: 标签数据。
""" """
data = np.loadtxt(filepath, delimiter=',', dtype=str) data = np.loadtxt(filepath, delimiter=',', dtype=str)
X = data[:, :-1].astype(float) # 特征数据
y = data[:, -1] # 标签数据 # 检查数据的维度
if data.ndim == 1:
# 如果数据是一维的,可能是因为文件只有一行
data = np.expand_dims(data, axis=0)
# 特征数据
X = data[:, :-1].astype(float) # 所有列,除了最后一列
# 标签数据
y = data[:, -1] # 最后一列
# 将标签转换为 -1 和 1 # 将标签转换为 -1 和 1
y = np.where(y == '1', 1, -1) # 假设标签为 '1' 表示死亡,其他为存活 y = np.where(y == '1', 1, -1) # 假设标签为 '1' 表示死亡,其他为存活