generated from LufsX/Experiment-LogReg
This commit is contained in:
+2
-9
@@ -20,8 +20,8 @@ import numpy as np
|
|||||||
"""
|
"""
|
||||||
请在这里填写学号和姓名,不填写即成绩无效。
|
请在这里填写学号和姓名,不填写即成绩无效。
|
||||||
"""
|
"""
|
||||||
id = "202210423120"
|
id = ""
|
||||||
name = "袁焜"
|
name = ""
|
||||||
|
|
||||||
# 这里写自己的代码实现
|
# 这里写自己的代码实现
|
||||||
import numpy as np
|
import numpy as np
|
||||||
@@ -139,12 +139,5 @@ if __name__ == "__main__":
|
|||||||
# 测试模型
|
# 测试模型
|
||||||
final_test_accuracy = accuracy(X_test, y_test, final_weights)
|
final_test_accuracy = accuracy(X_test, y_test, final_weights)
|
||||||
print(f"最终测试集的准确率: {final_test_accuracy:.4f}")
|
print(f"最终测试集的准确率: {final_test_accuracy:.4f}")
|
||||||
# 加载测试集
|
|
||||||
X_test, y_test = load_data("./data/horse-colic.test")
|
|
||||||
|
|
||||||
# 训练对率回归模型
|
|
||||||
weights = train_logreg(X_train, y_train, learning_rate=0.01, iterations=1000)
|
|
||||||
|
|
||||||
# 测试单个数据
|
|
||||||
y_pred = predict_logreg(X_test[11], weights)
|
|
||||||
print(f"预测结果: {y_pred}, 实际结果: {y_test[11]}")
|
|
||||||
|
|||||||
Reference in New Issue
Block a user