feature_selection.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:Default-Credit-Card-Prediction 作者: AlexPnt 项目源码 文件源码
def rfe_selection(X,y,n_features):
    """
    Performs the Recursive Feature Elimination method and selects the top ranking features

    Keyword arguments:
    X -- The feature vectors
    y -- The target vector
    n_features -- n best ranked features
    """

    if verbose:
        print '\nPerforming Feature Selection based on the Recursive Feature Elimination method ...'

    clf=RandomForestClassifierWithCoef(n_estimators=10,n_jobs=-1)
    fs= RFE(clf, n_features, step=1)
    fs= fs.fit(X,y)
    ranks=fs.ranking_

    feature_indexes=[]
    for i in xrange(len(ranks)):
        if ranks[i]==1:
            feature_indexes+=[i]

    return X[:,feature_indexes[0:n_features]],feature_indexes[0:n_features]     #return selected features and original index features
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号