From d217ae1b24aed7ace78bcda6bef0080079bfe529 Mon Sep 17 00:00:00 2001 From: mogu-king <1547976000@qq.com> Date: Sun, 3 Nov 2024 04:30:30 +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 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/function.py b/function.py index 08e4711..bc95f6b 100644 --- a/function.py +++ b/function.py @@ -78,7 +78,7 @@ def train_logreg(X, y, learning_rate=0.01, num_iterations=1000, regularization_s return weights -# 对率回归预测函数 +# 使用 0.4 阈值的对率回归预测函数 def predict_logreg(inX, weights): """ 对率回归预测函数。 @@ -91,7 +91,7 @@ def predict_logreg(inX, weights): - int: 预测的分类标签。 """ probability = 1 / (1 + np.exp(-np.dot(inX, weights))) - return 1 if probability >= 0.5 else 0 + return 1 if probability >= 0.4 else 0 if __name__ == "__main__": # 以下代码可用于测试,可自行随意修改