关于多项式逻辑回归,进行网格搜索时报错
来源:9-7 scikit-learn中的逻辑回归
lemonlxn
2019-03-13
老师好,今天我想寻找多项式逻辑回归中,最合适的 degree 、C、penalty,但运行几次都报错,报错原因如下:
ValueError: Invalid parameter C for estimator Pipeline
大概意思是,对于管道 Pipeline 而言,是无效参数,请问老师在多项式逻辑回归中,能进行网格搜索吗?
相关代码如下:
from sklearn.model_selection import GridSearchCV
from sklearn.pipeline import Pipeline
from sklearn.linear_model import LogisticRegression
from sklearn.preprocessing import StandardScaler,PolynomialFeatures
def PolyLogisticRegression2(degree,C,penalty='l2'):
return Pipeline([
('poly',PolynomialFeatures(degree=degree)),
('stand',StandardScaler()),
('log',LogisticRegression(C=C,penalty=penalty))
])
poly_log_reg2 = PolyLogisticRegression2(20,1,'l2')
param_grid2 = [{
'degree':[i for i in range(10,20)],
'C':[i for i in np.arange(0.1,1,0.1)],
'penalty':['l1','l2']
}]
grid_search = GridSearchCV(poly_log_reg2,param_grid2,verbose=2,n_jobs=-1)
grid_search.fit(X_train,y_train)
写回答
1回答
-
022019-03-13
相似问题
关于岭回归和多项式回归
回答 1
使用网格搜索时jupyter报错
回答 1