关于特征选择的几种算法

利用随机森林进行特征选择,输出特征的重要程度

from sklearn.datasets import load_boston
from sklearn.ensemble import RandomForestRegressor
import numpy as np

#Load boston housing dataset as an example
boston = load_boston()
X = boston["data"]
Y = boston["target"]
names = boston["feature_names"]
rf = RandomForestRegressor()
rf.fit(X, Y)
print("Features sorted by their score:")
print(sorted(zip(map(lambda x: round(x, 4), rf.feature_importances_), names),
             reverse=True))

result:

Features sorted by their score:
[(0.46600000000000003, 'LSTAT'), (0.34060000000000001, 'RM'), (0.069000000000000006, 'DIS'), (0.042200000000000001, 'CRIM'), (0.0207, 'NOX'), (0.0143, 'AGE'), (0.012500000000000001, 'TAX'), (0.0124, 'B'), (0.010500000000000001, 'PTRATIO'), (0.0080000000000000002, 'INDUS'), (0.0025000000000000001, 'RAD'), (0.001, 'ZN'), (0.00040000000000000002, 'CHAS')]

推荐阅读:
http://www.cnblogs.com/hhh5460/p/5186226.html

http://www.cnblogs.com/qqhfeng/p/5341840.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值