generated from LufsX/Experiment-LogReg
This commit is contained in:
+6
-1
@@ -1,5 +1,5 @@
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
from sklearn.preprocessing import StandardScaler
|
from sklearn.preprocessing import StandardScaler, PolynomialFeatures
|
||||||
|
|
||||||
id = "202210423124"
|
id = "202210423124"
|
||||||
name = "刘子豪"
|
name = "刘子豪"
|
||||||
@@ -81,9 +81,14 @@ if __name__ == "__main__":
|
|||||||
scaler = StandardScaler()
|
scaler = StandardScaler()
|
||||||
X_train = scaler.fit_transform(X_train)
|
X_train = scaler.fit_transform(X_train)
|
||||||
|
|
||||||
|
# 使用 PolynomialFeatures 生成多项式特征
|
||||||
|
poly = PolynomialFeatures(degree=2, include_bias=False)
|
||||||
|
X_train_poly = poly.fit_transform(X_train)
|
||||||
|
|
||||||
# 加载测试集
|
# 加载测试集
|
||||||
X_test, y_test = load_data("./data/horse-colic.test")
|
X_test, y_test = load_data("./data/horse-colic.test")
|
||||||
X_test = scaler.transform(X_test) # 使用同一标准化参数
|
X_test = scaler.transform(X_test) # 使用同一标准化参数
|
||||||
|
X_test_poly = poly.transform(X_test) # 应用相同的多项式特征转换
|
||||||
|
|
||||||
# 训练对率回归模型
|
# 训练对率回归模型
|
||||||
weights = train_logreg(X_train, y_train, learning_rate=0.01, iterations=1000, reg_lambda=0.01)
|
weights = train_logreg(X_train, y_train, learning_rate=0.01, iterations=1000, reg_lambda=0.01)
|
||||||
|
|||||||
Reference in New Issue
Block a user