@@ -0,0 +1,1892 @@
+import pandas as pd%0Aimport numpy as np%0Afrom xgboost.sklearn import XGBClassifier%0Afrom sklearn.preprocessing import LabelEncoder%0Afrom sklearn.cross_validation import cross_val_score%0Afrom sklearn.cross_validation import KFold%0Afrom sklearn.feature_selection import SelectFromModel%0A%0Afrom utils.metrics import ndcg_scorer%0A%0Apath = '../data/processed/'%0Atrain_users = pd.read_csv(path + 'ohe_count_processed_train_users.csv')%0Ay_train = train_users%5B'country_destination'%5D%0Atrain_users.drop('country_destination', axis=1, inplace=True)%0Atrain_users.drop('id', axis=1, inplace=True)%0Atrain_users = train_users.fillna(-1)%0Ax_train = train_users.values%0Alabel_encoder = LabelEncoder()%0Aencoded_y_train = label_encoder.fit_transform(y_train)%0A%0Aclf = XGBClassifier(n_estimators=1, nthread=-1, seed=42)%0Akf = KFold(len(x_train), n_folds=5, random_state=42)%0A%0Ascore = cross_val_score(clf, x_train, encoded_y_train,%0A                        cv=kf, scoring=ndcg_scorer)%0Aprint 'Score:', score.mean()%0A%0A%0Aclass CustomXGB(XGBClassifier):%0A%0A    @property%0A    def feature_importances_(self):%0A        %22%22%22Return the feature importances (the higher, the more important the%0A           feature).%0A        Returns%0A        -------%0A        feature_importances_ : array, shape = %5Bn_features%5D%0A        %22%22%22%0A        booster = self.booster()%0A        scores = booster.get_fscore()%0A        all_scores = pd.Series(np.zeros(x_train.shape%5B1%5D))%0A        scores = pd.Series(scores)%0A        scores.index = scores.index.map(lambda x: x%5B1:%5D).astype(int)%0A        final_scores = all_scores + scores%0A        importances = final_scores.fillna(0).values%0A        return importances%0A%0A%0Acustom = CustomXGB(n_estimators=1, seed=42, nthread=-1)%0Amodel = SelectFromModel(custom)%0AX_new = model.fit_transform(x_train, encoded_y_train)%0A%0Ascore = cross_val_score(clf, X_new, encoded_y_train,%0A                        cv=kf, scoring=ndcg_scorer)%0Aprint 'Score:', score.mean()%0A

Add structure to feature selection script