特征选择__过滤型

过滤型--方差过滤法 过滤方差较低的特征

from sklearn.feature_selection import VarianceThreshold
# 方差阈值
selector = VarianceThreshold(threshold=2)
selector.fit_transform(data)  
# 每个特征的方差
selector.variances_ 

过滤型--## 卡方检验 考虑当前特征和目标特征的相关性,但是容易删除有用的关联特征

from sklearn.feature_selection import SelectKBest
from sklearn.feature_selection import chi2
# 生成一个新的数组
data_new = SelectKBest(chi2,k=2).fit_transform(data,target)
data_new

你可能感兴趣的:(特征选择__过滤型)