from sklearn.feature_selection import VarianceThreshold
#数据预处理过滤式特征选取VarianceThreshold模型
def test_VarianceThreshold():
X=[[100,1,2,3],
[100,4,5,6],
[100,7,8,9],
[101,11,12,13]]
selector=VarianceThreshold(1)
selector.fit(X)
print("Variances is %s"%selector.variances_)
print("After transform is %s"%selector.transform(X))
print("The surport is %s"%selector.get_support(True))
print("After reverse transform is %s"%selector.inverse_transform(selector.transform(X)))
#调用test_VarianceThreshold()
test_VarianceThreshold()

标签:python,VarianceThreshold,transform,selector,test,print,100,吴裕雄
来源: https://www.cnblogs.com/tszr/p/10802018.html
这段代码展示了如何使用Python的sklearn库中VarianceThreshold类进行数据预处理,通过设置阈值过滤掉低方差特征。在示例中,创建了一个4列的数据集,并设置了阈值为1,然后进行特征选择、转换、获取支持向量及反向转换操作。
287

被折叠的 条评论
为什么被折叠?



