# -*- coding: utf-8 -*-
"""
Created on Mon Aug 21 10:57:29 2017
@author: 飘的心
"""
#过滤式特征选择
#根据方差进行选择,方差越小,代表该属性识别能力很差,可以剔除
from sklearn.feature_selection import VarianceThreshold
x=[[100,1,2,3],
[100,4,5,6],
[100,7,8,9],
[101,11,12,13]]
selector=VarianceThreshold(1) #方差阈值值,
selector.fit(x)
selector.variances_ #展现属性的方差
selector.transform(x)#进行特征选择
selector.get_support(True) #选择结果后,特征之前的索引
selector.inverse_transform(selector.transform(x)) #将特征选择后的结果还原成原始数据
#被剔除掉的数据,显示为0
#单变量特征选择
from sklearn.feature_selection import SelectKBest,f_classif
x=[[1,2,3,4,5],
[5,4,3,2,1],
[3,3,3,3,3],
[1,1,1,1,1]]
y=[0,1,0,1]
selector=SelectKBest(score_func=f_classif,k=3)#选择3个特征,指标使用的是方差分析F值
selector.fit(x,y)
selector.