generated from LufsX/Experiment-LogReg
This commit is contained in:
+3
-3
@@ -1,6 +1,7 @@
|
|||||||
# function.py
|
# function.py
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from sklearn.preprocessing import StandardScaler
|
from sklearn.preprocessing import StandardScaler
|
||||||
|
from itertools import product
|
||||||
|
|
||||||
"""
|
"""
|
||||||
实验说明:
|
实验说明:
|
||||||
@@ -28,7 +29,7 @@ name = "程悦"
|
|||||||
def sigmoid(z):
|
def sigmoid(z):
|
||||||
return 1.0 / (1 + np.exp(-z))
|
return 1.0 / (1 + np.exp(-z))
|
||||||
|
|
||||||
def train_logreg(X, y, learning_rate=0.01, iterations=1000, batch_size=32, regularization=None, lambda_reg=0.1):
|
def train_logreg(X, y, learning_rate=0.01, iterations=1000, batch_size=16, regularization=L1, lambda_reg=0.1):
|
||||||
"""
|
"""
|
||||||
对率回归训练函数。
|
对率回归训练函数。
|
||||||
|
|
||||||
@@ -129,8 +130,7 @@ if __name__ == "__main__":
|
|||||||
X_test, y_test = load_data("./data/horse-colic.test")
|
X_test, y_test = load_data("./data/horse-colic.test")
|
||||||
|
|
||||||
# 训练对率回归模型
|
# 训练对率回归模型
|
||||||
weights = train_logreg(X_train, y_train, learning_rate=0.01, iterations=1000, batch_size=32, regularization='L2',
|
weights = train_logreg(X_train, y_train)
|
||||||
lambda_reg=0.1)
|
|
||||||
|
|
||||||
# 测试单个数据
|
# 测试单个数据
|
||||||
y_pred = predict_logreg(X_test[11], weights)
|
y_pred = predict_logreg(X_test[11], weights)
|
||||||
|
|||||||
Reference in New Issue
Block a user