Python scikit-learn,特征降维(降低特征的数量),特征选择,VarianceThreshold (删除低方差的特征)

特征选择的原因:1、冗余:部分特征的相关度高,容易消耗计算性能。 2、噪声(过拟合):部分特征对预测结果有负影响

特征选择就是单纯地从提取到的所有特征中选择部分特征作为训练集特征,特征在选择前和选择后可以改变值、也可以不改变值,但是选择后的特征维数肯定比选择前小,毕竟我们只选择了其中的一部分特征。

特征选择的主要方法:一、Filter(过滤式):VarianceThreshold。 二、 Embedded(嵌入式):正则化、决策树。 三、 Wrapper(包裹式)。 四、神经网络

demo.py(特征降维,特征选择,VarianceThreshold):

from sklearn.feature_selection import VarianceThreshold


# 特征选择  VarianceThreshold删除低方差的特征(删除差别不大的特征)
var = VarianceThreshold(threshold=1.0)   # 将方差小于等于1.0的特征删除。 默认threshold=0.0
data = var.fit_transform([[0, 2, 0, 3], [0, 1, 4, 3], [0, 1, 1, 3]])

print(data)
'''
[[0]
 [4]
 [1]]
'''

猜你喜欢

转载自blog.csdn.net/houyanhua1/article/details/87911582
今日推荐