generated from LufsX/Experiment-LogReg
This commit is contained in:
+2
-2
@@ -31,7 +31,7 @@ name = "李燕如"
|
|||||||
def sigmoid(x):
|
def sigmoid(x):
|
||||||
return 1 / (1 + np.exp(-x))
|
return 1 / (1 + np.exp(-x))
|
||||||
|
|
||||||
def train_logreg(X, y, learning_rate=0.01, iterations=1000, regularization=0.01):
|
def train_logreg(X, y, learning_rate=0.001, iterations=2000, regularization=0.01):
|
||||||
m, n = X.shape
|
m, n = X.shape
|
||||||
weights = np.zeros(n)
|
weights = np.zeros(n)
|
||||||
for _ in range(iterations):
|
for _ in range(iterations):
|
||||||
@@ -95,7 +95,7 @@ def main():
|
|||||||
X_test = scaler.transform(X_test)
|
X_test = scaler.transform(X_test)
|
||||||
|
|
||||||
# 训练模型
|
# 训练模型
|
||||||
weights = train_logreg(X_train, y_train, learning_rate=0.01, iterations=1000, regularization=0.1)
|
weights = train_logreg(X_train, y_train, learning_rate=0.001, iterations=2000, regularization=0.01)
|
||||||
|
|
||||||
# 预测测试集
|
# 预测测试集
|
||||||
y_pred = [predict_logreg(x, weights) for x in X_test]
|
y_pred = [predict_logreg(x, weights) for x in X_test]
|
||||||
|
|||||||
Reference in New Issue
Block a user