from sklearn.feature_selection import SelectPercentile,f_classif

#数据预处理过滤式特征选取SelectPercentile模型
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=SelectPercentile(score_func=f_classif,percentile=10)
    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()