8.特征选择,过滤式

用过滤法对以下数据进行特征选择:

                             [[0,2,0,3],

                              [0,1,4,3],

                              [0,1,1,3]]

要求:

1、Variance Threshold(threshold =1.0)

算法运用:

from sklearn.feature_selection import VarianceThreshold
import numpy as np

X=np.array([[0,2,0,3],[0,1,4,3],[0,1,1,3]])
for i in range(4):
    print("原数据:",X[:,i],"方差:",np.var(X[:,i])) #方差
def var():
    # 特征选择-删除指定方差的特征
    for i in range(10):
        var = VarianceThreshold(threshold=i)
        print(i)
        data = var.fit_transform([[0,2,0,3],[0,1,4,3],[0,1,1,3]])
        print("去除方差小于或等于",i,"后的数据为:",data)
# 调用
if __name__ == '__main__':
    var()

 

 

 

 结果

 

posted @ 2020-04-27 09:53  Chock17  阅读(324)  评论(0编辑  收藏  举报