树模型天然会对特征进行重要性排序,以分裂数据集,构建分支;

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))

相关文章:

  • 2021-06-06
  • 2021-09-21
  • 2021-10-10
  • 2022-12-23
  • 2021-07-28
  • 2021-09-26
  • 2021-10-28
  • 2021-06-21
猜你喜欢
  • 2022-12-23
  • 2021-07-04
  • 2022-12-23
  • 2021-07-18
  • 2021-07-12
  • 2022-03-01
相关资源
相似解决方案