Machine learning feature selection filter

Source Address: https://www.cnblogs.com/bjwu/p/9103002.html

 

Filter- remove all low variance feature

Code:

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)

Return value filtering characteristics variance is less than 0.2, the average variance information:

 

 

Filter- univariate feature selection

SelectKBest Remove all those features in addition to the top-rated K feature outside

Code:

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- recursive feature elimination (The RFE)

 

Select feature embedded-

 

Guess you like

Origin www.cnblogs.com/bai2018/p/12530711.html