在用sklearn的时候经常用到feature_importances_ 来做特征筛选,那么出现:

AttributeError: 'GridSearchCV' object has no attribute 'feature_importances_'

怎么办?
原因:GridSearchCV加入了网格搜索。
解决方法:在feature_importances_前面加入best_estimator_

 print("特征重要性:",RF.best_estimator_.feature_importances_)#如果用了网格搜索就需加best_estimator_

完美解决!!!

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐