Print "Performing greedy feature selection ..." score_hist = []n = 10good_features = Set ([]) # greedy Feature selection LOOPW Hile 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 () C5/>score = Cv_loop (Xt, y, model, N) Scores.append ((score, F)) print "Feature:%i Mean AUC:%f"% (f, score) g Ood_features.add (sorted (scores) [ -1][1]) Score_hist.append (sorted (scores) [-1]) print "Current features:% S "% sorted (list (good_features))
Notice is not over yet:
# Remove Last added feature from Good_featuresgood_features.remove (Score_hist[-1][1])
From Kaggle
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Machine learning in coding (Python): Use greedy search "for feature selection"