from sklearn.feature_selection import SelectKBest,f_classif

#数据预处理过滤式特征选取SelectKBest模型
def test_SelectKBest():
    X=[[1,2,3,4,5],
          [5,4,3,2,1],
          [3,3,3,3,3,],
          [1,1,1,1,1]]
    y=[0,1,0,1]
    print("before transform:",X)
    selector=SelectKBest(score_func=f_classif,k=3)
    selector.fit(X,y)
    print("scores_:",selector.scores_)
    print("pvalues_:",selector.pvalues_)
    print("selected index:",selector.get_support(True))
    print("after transform:",selector.transform(X))
    
#调用test_SelectKBest()
test_SelectKBest()