机器学习中的特征选择filter


来源地址:https://www.cnblogs.com/bjwu/p/9103002.html

 

Filter-移除低均方差的特征

代码:

from sklearn.feature_selection import VarianceThreshold
X = [[0, 0, 1], [0, 1, 0], [1, 0, 0], [0, 1, 1], [0, 1, 0], [0, 1, 1]]
sel = VarianceThreshold(threshold=(0.2)
sel.fit_transform(X)

返回值过滤了方差小于0.2的特征,方差信息为:

 

 

Filter-单变量特征选择

SelectKBest 移除那些除了评分最高的 K 个特征之外的所有特征

代码:

from sklearn.datasets import load_iris
from sklearn.feature_selection import SelectKBest
from sklearn.feature_selection import chi2
iris = load_iris()
X, y = iris.data, iris.target
X.shape
X_new = SelectKBest(chi2, k=2).fit_transform(X, y)
X_new.shape

  

wrapper-递归式特征消除(RFE)

 

embedded-选取特征

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM