generated from LufsX/Challenge-SVM
This commit is contained in:
+10
-2
@@ -90,8 +90,16 @@ def load_data(filepath):
|
||||
- np.array: 标签数据。
|
||||
"""
|
||||
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
|
||||
y = np.where(y == '1', 1, -1) # 假设标签为 '1' 表示死亡,其他为存活
|
||||
|
||||
Reference in New Issue
Block a user