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)