码迷,mamicode.com
首页 > 编程语言 > 详细

machine learning in coding(python):使用贪心搜索【进行特征选择】

时间:2015-08-11 21:31:26      阅读:269      评论:0      收藏:0      [点我收藏+]

标签:机器学习   machine learning   贪心搜索进行特征选择   特征选择   贪心搜索   



print "Performing greedy feature selection..."
score_hist = []
N = 10
good_features = set([])
# Greedy feature selection loop
while len(score_hist) < 2 or score_hist[-1][0] > score_hist[-2][0]:
    scores = []
    for f in range(len(Xts)):
        if f not in good_features:
            feats = list(good_features) + [f]
            Xt = sparse.hstack([Xts[j] for j in feats]).tocsr()
            score = cv_loop(Xt, y, model, N)
            scores.append((score, f))
            print "Feature: %i Mean AUC: %f" % (f, score)
    good_features.add(sorted(scores)[-1][1])
    score_hist.append(sorted(scores)[-1])
    print "Current features: %s" % sorted(list(good_features))



注意还没结束:

# Remove last added feature from good_features
good_features.remove(score_hist[-1][1])




from kaggle

版权声明:本文为博主原创文章,未经博主允许不得转载。

machine learning in coding(python):使用贪心搜索【进行特征选择】

标签:机器学习   machine learning   贪心搜索进行特征选择   特征选择   贪心搜索   

原文地址:http://blog.csdn.net/mmc2015/article/details/47426437

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!