作业8 特征选择
用过滤法对以下数据进行特征选择:
[[0,2,0,3],
[0,1,4,3],
[0,1,1,3]]
要求:
1、Variance Threshold(threshold =0.0)
from sklearn.feature_selection import VarianceThreshold # 特征选择API # 特征选择--删除低方差的特征 def var(): var = VarianceThreshold(threshold = 0.0) data = var.fit_transform([[0,2,0,3],[0,1,4,3],[0,1,1,3]]) print(data) return None if __name__ == "__main__": var()
运行结果:
2、Variance Threshold(threshold =1.0)
from sklearn.feature_selection import VarianceThreshold # 特征选择API # 特征选择--删除低方差的特征 def var(): var = VarianceThreshold(threshold = 1.0) data = var.fit_transform([[0,2,0,3],[0,1,4,3],[0,1,1,3]]) print(data) return None if __name__ == "__main__": var()
运行结果:
3、Variance Threshold(threshold =3.0)
from sklearn.feature_selection import VarianceThreshold # 特征选择API # 特征选择--删除低方差的特征 def var(): var = VarianceThreshold(threshold = 2.0) data = var.fit_transform([[0,2,0,3],[0,1,4,3],[0,1,1,3]]) print(data) return None if __name__ == "__main__": var()
运行结果: