python - 特征重要性分布图
问题描述
我基于此在我的数据框中进行了特征选择: https ://towardsdatascience.com/feature-selection-using-random-forest-26d7b747597f
在第 7 部分,为了绘制重要性分布,提供了以下代码:
pd.series(sel.estimator_,feature_importances_,.ravel()).hist()
我认为没有语法错误应该是这样的:
pd.series(sel.estimator_,feature_importances_.ravel()).hist()
我收到了这个错误:
AttributeError:模块“熊猫”没有属性“系列”
解决方案
pd.Series(sel.estimator_.feature_importances_.ravel()).hist()
是“系列”而不是“系列”
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.hist.html
绘制特征重要性
importances = sel.estimator_.feature_importances_
indices = np.argsort(importances)[::-1]
# X is the train data used to fit the model
plt.figure()
plt.title("Feature importances")
plt.bar(range(X.shape[1]), importances[indices],
color="r", align="center")
plt.xticks(range(X.shape[1]), indices)
plt.xlim([-1, X.shape[1]])
plt.show()
推荐阅读
- git - 使用 reposurgeon 将多项目 Subversion 存储库迁移到 Git
- swift - Swift:“Hashable.hashValue”作为协议要求已被弃用
- linux - 没有轮询,有没有办法让另一个线程“重置”睡眠线程的计时器,使其睡眠时间更长?
- javascript - 超过最大更新深度。反应使用效果
- android - 滚动片段时隐藏BottomNavigationView(WebView)
- regex - 使用正则表达式为 Zapier 提取根域
- swift - 在 SwiftUI 中的视图之间移动
- powershell - Powershell:获取两个随机的独立数字
- ruby - 如果 Solr 不可访问,则在 Ruby Heroku 应用程序中忽略 Solr
- exception - javafx.fxml.LoadException:元素未定义默认属性