我正在構建隨機森林演算法,目標是預測哪些特征更重要。我有條形圖顯示隨機森林內置特征重要性的特征重要性。與較大的條相比,是否有機會過濾掉相對較小的資料以及如何實作這一點。我想做這些,因為下面的這些圖片一團糟:

輸入代碼:
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")
uj5u.com熱心網友回復:
通過過濾sorted_idx變數,您應該能夠這樣做:
sorted_idx = rf.feature_importances_.argsort()[:5]
顯然,您可以選擇要繪制的任意數量的特征,而不是 5 個。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/493421.html
標籤:Python 熊猫 matplotlib 机器学习 条形图
下一篇:找出資料框中的值是否增加了十位
