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

This commit is contained in:
2024-11-14 16:59:55 +08:00
parent 1b033a9e86
commit 4304c8e1ef
+6 -13
View File
@@ -33,20 +33,13 @@ def load_data(filepath):
labels = []
with open(filepath, 'r') as file:
for line in file:
line = line.strip().split()
if len(line) > 1:
label = line[0]
if label == "死亡":
label = 0
elif label == "安乐死":
label = 1
elif label == "存活":
label = 2
labels.append(label)
features = [float(x) if x != '?' else 0.0 for x in line[1:]]
fields = line.strip().split()
if '?' in fields: # 处理缺失值
fields = [0 if f == '?' else float(f) for f in fields]
features = np.array(fields[:-1], dtype=float)
label = int(fields[-1]) # 确保标签未合并
data.append(features)
labels.append(label)
return np.array(data), np.array(labels)
def train_svm(X, y, learning_rate=0.01, iterations=1000):