从 GridSearchCV 获取特征重要性

Get feature importance from GridSearchCV

有没有办法从 sklearn 的 GridSearchCV 中获取特征重要性?

例如:

from sklearn.model_selection import GridSearchCV
print("starting grid search ......")
optimized_GBM = GridSearchCV(LGBMRegressor(),
                             params,
                             cv=3,
                             n_jobs=-1)
# 
optimized_GBM.fit(tr, yvar)
preds2 = optimized_GBM.predict(te)

有什么方法可以访问特征重要性?

可能是

optimized_GBM.feature_importances_

知道了。它是这样的:

optimized_GBM.best_estimator_.feature_importance()

如果您通过管道发生 运行 这件事并接收 object has no attribute 'feature_importance' 尝试 optimized_GBM.best_estimator_.named_steps["step_name"].feature_importances_

其中 step_name 是管道中的相应名称

这个有效

optimized_GBM.best_estimator_.feature_importances_

这取决于您选择的型号。如果你选择 SVM,你不会有特征重要性参数,但在决策树中你会得到它