來源地址: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-選取特征