如何在条形图上拥有更少的条形图?

发布于 2025-02-08 22:29:33 字数 609 浏览 2 评论 0原文

我正在构建随机森林算法,目的是预测哪些功能更重要。我的条形图显示了从随机森林内置特征重要性中重要的特征。与较大的条形相比,是否有机会过滤数据相对较小的数据以及如何实施此数据。我想这样做是因为下面的这些图片上有一团糟:

”在此处输入图像说明”

输入代码:

rf = RandomForestRegressor(n_estimators=100, max_depth=3)
rf.fit(X_train, y_train)

sorted_idx = rf.feature_importances_.argsort()
plt.figure(figsize=(8, 30))
plt.barh(X_train.columns[sorted_idx], rf.feature_importances_[sorted_idx])
plt.xlabel("Random Forest Feature Importance")

I am building Random forest algorithm, the goal is to predict which features are more important. And I have Bar graph showing features importance from Random Forest Built-in Feature Importance. Is there a chance to filter out data that are relatively smaller compared to larger bars and how to implement this. I want to do these because there is a mess on these picture below:

enter image description here

Input code:

rf = RandomForestRegressor(n_estimators=100, max_depth=3)
rf.fit(X_train, y_train)

sorted_idx = rf.feature_importances_.argsort()
plt.figure(figsize=(8, 30))
plt.barh(X_train.columns[sorted_idx], rf.feature_importances_[sorted_idx])
plt.xlabel("Random Forest Feature Importance")

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沉默的熊 2025-02-15 22:29:33

通过过滤sorted_idx变量,您应该能够这样做:

sorted_idx = rf.feature_importances_.argsort()[:5]

显然,您可以采用任何要绘制的功能。

By filtering the sorted_idx variable, you should be able to do so:

sorted_idx = rf.feature_importances_.argsort()[:5]

Instead of 5, you can obviously take whatever number of features you want to be plotted.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文