问题描述
这个问题之前有人问过,here 和 here。当我尝试这些答案时,我的错误消息是我的模型没有 coef
属性。我使用管道、网格搜索和目标转换。我可以访问模型本身,但我的错误消息是我的模型 SGDRegressor 没有属性 coef_。
cv_inner = KFold(n_splits=5,shuffle=True)
params = {'model__regressor__penalty':['elasticnet'],'model__regressor__l1_ratio': [0.1,0.3]
}
mymodel = Pipeline(steps = [('preprocessor',preprocessor),('model',TTR(regressor=SGDRegressor(n_jobs=-1),transformer=qt))
])
optimize_hparams = gridsearchcv(
estimator = mymodel,param_grid=params,n_jobs = -1,cv=cv_inner,scoring='neg_mean_absolute_error')
optimize_hparams.fit(X,y)
optimize_hparams.best_estimator_.named_steps['model'].regressor.coef_
# 'SGDRegressor' object has no attribute 'coef_'
解决方法
<button id="myBtn" type="button">Power Virtual Agent</button>
<div id="myModal" class="modal">
<div class="modal-content" style="background-color: #ffd933">
<span class="close">×</span>
<div id="chatwindow">
<div id="heading">
<div><span>SSO Test Bot</span></div>
</div>
<div id="webchat"></div>
</div>
</div>
</div>
属性 TransformedTargetRegressor
是输入的未拟合估计量。您需要 regressor
,拟合回归量。 (注意文档说 regressor_
在拟合之前被克隆,这就是属性保持未拟合的原因。)