From b71e1fafc2c482aaa6600ed18b8e6762cef832d5 Mon Sep 17 00:00:00 2001 From: Dengddd <3149942468@qq.com> Date: Thu, 31 Oct 2024 15:11:21 +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 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/function.py b/function.py index fbac677..f1f37fa 100644 --- a/function.py +++ b/function.py @@ -32,8 +32,8 @@ def sigmoid(z): """计算sigmoid函数""" return 1 / (1 + np.exp(-z)) -def train_logreg(X, y, learning_rate=0.01, iterations=1000, 2_penalty=0.01): - """对率回归训练函数。""" +def train_logreg(X, y, learning_rate=0.01, iterations=1000, l2_penalty=0.01): + """对率回归训练函数,包括L2正则化。""" weights = np.zeros(X.shape[1]) for _ in range(iterations): @@ -44,6 +44,7 @@ def train_logreg(X, y, learning_rate=0.01, iterations=1000, 2_penalty=0.01): return weights + def predict_logreg(X, weights): """使用训练好的权重预测标签""" z = np.dot(X, weights)