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

This commit is contained in:
2024-10-31 17:57:04 +08:00
parent c77ff5fa6a
commit 288e0bdd99
+24
View File
@@ -25,3 +25,27 @@ def load_data(filepath):
scaler = StandardScaler()
data = scaler.fit_transform(data)
return data, labels
# 测试代码
if __name__ == "__main__":
# 指定数据文件路径
filepath = "./data/horse-colic.data"
# 加载数据
X, y = load_data(filepath)
print("数据加载成功。")
# 训练模型
model = train_logreg(X, y)
print("模型训练完成。")
# 随机选择一个样本进行预测测试
sample = X[0]
actual_label = y[0]
predicted_label = predict_logreg(sample, model)
print(f"预测结果: {predicted_label}, 实际结果: {actual_label}")
# 计算测试集上的准确率
correct_predictions = sum(predict_logreg(X[i], model) == y[i] for i in range(len(y)))
accuracy = correct_predictions / len(y)
print(f"测试集准确率: {accuracy:.2f}")