From 468b21dcfe1ff6e90fe609a5036f93246f0bc84d Mon Sep 17 00:00:00 2001 From: llll <2992513220@qq.com> Date: Thu, 31 Oct 2024 23:20:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20function.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- function.py | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/function.py b/function.py index 81ca379..bc959e9 100644 --- a/function.py +++ b/function.py @@ -95,18 +95,4 @@ def predict_logreg(inX, weights): """ inX = np.c_[1, inX] # 添加截距项 prob = sigmoid(np.dot(inX, weights)) - return 1 if prob > 0.5 else 0 - -if __name__ == "__main__": - # 加载训练集 - X_train, y_train = load_data("./data/horse-colic.data") - - # 加载测试集 - X_test, y_test = load_data("./data/horse-colic.test") - - # 训练对率回归模型 - weights = train_logreg(X_train, y_train) - - # 测试单个数据 - y_pred = predict_logreg(X_test[11], weights) - print(f"预测结果: {y_pred}, 实际结果: {int(y_test[11])}") \ No newline at end of file + return 1 if prob > 0.5 else 0 \ No newline at end of file