用过滤法对以下数据进行特征选择:
[[0,2,0,3],
[0,1,4,3],
[0,1,1,3]]
要求:
1、Variance Threshold(threshold =1.0)
2、将结果截图
过滤方差0到2,因为数据太少,不能满足过滤方差为3的条件,过滤后将无特征值。
# -*- coding:utf-8 -*- from sklearn.feature_selection import VarianceThreshold def var(): test = [[0,2,0,3], [0,1,4,3], [0,1,1,3]] for i in range(0,3): print(i) var = VarianceThreshold(threshold=float(i)) data = var.fit_transform(test) print("去除方差小于",i,"的值: ",data) if __name__ == "__main__": var()
运行结果: