generated from LufsX/Experiment-LogReg
This commit is contained in:
+9
-4
@@ -69,7 +69,7 @@ def load_data(filepath):
|
||||
"""
|
||||
data = []
|
||||
labels = []
|
||||
|
||||
|
||||
with open(filepath, 'r') as file:
|
||||
for line in file:
|
||||
line = line.strip().split()
|
||||
@@ -85,15 +85,20 @@ def load_data(filepath):
|
||||
continue
|
||||
|
||||
# 将特征转换为浮点数
|
||||
features = list(map(float, line[:-1]))
|
||||
label = int(line[-1])
|
||||
try:
|
||||
features = list(map(float, line[:-1])) # 所有特征转换为浮点数
|
||||
label = int(line[-1]) # 标签为整数
|
||||
except ValueError:
|
||||
# 如果遇到无法转换的值,则跳过这一行
|
||||
continue
|
||||
|
||||
# 添加到数据集
|
||||
data.append(features)
|
||||
labels.append(label)
|
||||
|
||||
|
||||
return np.array(data), np.array(labels)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# 加载训练集
|
||||
X_train, y_train = load_data("./data/horse-colic.data")
|
||||
|
||||
Reference in New Issue
Block a user