機器學習中的特征選擇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