【发布时间】:2021-12-08 23:25:03
【问题描述】:
我正在使用管道和 GridSearchCV 执行 LinearRegression 模型,但无法达到为 X_train 的每个特征计算的系数。
mlr_gridsearchcv = Pipeline(steps =[('preprocessor', preprocessor),
('gridsearchcv_lr', GridSearchCV(TransformedTargetRegressor(regressor= LinearRegression(),
func = np.log,inverse_func = np.exp), param_grid=parameter_lr, cv = nfolds,
scoring = ('r2','neg_mean_absolute_error'), return_train_score = True,
refit='neg_mean_absolute_error', n_jobs = -1))])
mlr_co2=mlr_gridsearchcv.fit(X_train,Y_train['co2e'])
我已尝试先获得 best_estimator_:
mlr_co2.named_steps['gridsearchcv_lr'].cv_results_.best_estimator_
我得到:
AttributeError: 'dict' object has no attribute 'best_estimator_'
如果我这样尝试:
mlr_co2.named_steps['gridsearchcv_lr'].best_estimator_.regressor.coef_
我明白了:
AttributeError: 'LinearRegression' object has no attribute 'coef_'
我尝试了其他组合,但似乎没有任何效果。
【问题讨论】:
标签: python machine-learning scikit-learn linear-regression