特征工程 —— 特征重要性排序(Random Forest)


樹模型天然會對特征進行重要性排序,以分裂數據集,構建分支;

1. 使用 Random Forest

from sklearn.datasets import load_boston
from sklearn.ensemble import RandomForestRegressor


boston_data = load_boston()
X = boston_data['data']
y = boston_data['target']
    # dir(boston_data) ⇒ 查看其支持的屬性為 ['DESCR', 'data', 'feature_names', 'target']
rf = RandomForestRegressor()
rf.fit(X, y)

print(sorted(zip(boston_data['feature_names'], map(lambda x: round(x, 4), 
                                                   rf.feature_importances_)),
             key=operator.itemgetter(1), reverse=True))


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM