generated from LufsX/Experiment-LogReg
This commit is contained in:
+3
-2
@@ -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)
|
||||||
|
|||||||
Reference in New Issue
Block a user