admin管理员组文章数量:1650766
我正在努力从我的RandomForestRegressor中取出功能重要性,我得到一个:
AttributeError: ‘GridSearchCV’ object has no attribute
‘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_
解决方法:
您正尝试在GridSearchCV对象上使用该属性.它不在那里.您实际需要做的是访问进行网格搜索的估算器.
访问属性:
importances = CV_RFR_regr.best_estimator_.feature_importances_
本文标签: 错误randomforestregressorpythonPythonRandomForestRegressor
版权声明:本文标题:python randomforestregressor_python–RandomForestRegressor和feature_importances_错误 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/dongtai/1729533506a1205115.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论