更新 function.py
Gitea Actions Experiment Test / Experiment-Actions (push) Successful in 11s

This commit is contained in:
2024-10-31 15:11:21 +08:00
parent 6f5078e205
commit b71e1fafc2
+3 -2
View File
@@ -32,8 +32,8 @@ def sigmoid(z):
"""计算sigmoid函数""" """计算sigmoid函数"""
return 1 / (1 + np.exp(-z)) 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]) weights = np.zeros(X.shape[1])
for _ in range(iterations): 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 return weights
def predict_logreg(X, weights): def predict_logreg(X, weights):
"""使用训练好的权重预测标签""" """使用训练好的权重预测标签"""
z = np.dot(X, weights) z = np.dot(X, weights)