【发布时间】:2018-04-17 02:38:41
【问题描述】:
我正在努力从我的 RandomForestRegressor 中提取特征重要性,我得到:
AttributeError: 'GridSearchCV' 对象没有属性 'feature_importances_'。
有人知道为什么没有属性吗?根据文档应该存在这个属性?
完整代码:
from sklearn.ensemble import RandomForestRegressor
from sklearn.model_selection import GridSearchCV
#Running a RandomForestRegressor GridSearchCV to tune the model.
parameter_candidates = {
'n_estimators' : [650, 700, 750, 800],
'min_samples_leaf' : [1, 2, 3],
'max_depth' : [10, 11, 12],
'min_samples_split' : [2, 3, 4, 5, 6]
}
RFR_regr = RandomForestRegressor()
CV_RFR_regr = GridSearchCV(estimator=RFR_regr, param_grid=parameter_candidates, n_jobs=5, verbose=2)
CV_RFR_regr.fit(X_train, y_train)
#Predict with testing set
y_pred = CV_RFR_regr.predict(X_test)
#Extract feature importances
importances = CV_RFR_regr.feature_importances_
【问题讨论】:
标签: python scikit-learn random-forest feature-extraction grid-search