@@ -0,0 +1,1979 @@
+# -*- coding: utf-8 -*-%0A%22%22%22%0ACreated on Wed Jun 15 23:05:21 2016%0A%0A@author: SISQUAKE%0A%22%22%22%0A%0Aimport numpy as np%0Afrom time import time%0Afrom operator import itemgetter%0Afrom scipy.stats import randint as sp_randint%0Afrom sklearn.grid_search import RandomizedSearchCV%0Afrom sklearn.ensemble import RandomForestClassifier%0Afrom numpy import genfromtxt%0A%0Aprint(__doc__)%0A%0Atrain_mat = genfromtxt('training.csv', delimiter=',')%0Ay = train_mat%5B:, 0%5D%0AX = train_mat%5B:, 1:%5D%0A%0A# build a classifier%0Aclf = RandomForestClassifier(n_estimators=50)%0A%0A# Utility function to report best scores%0A%0A%0Adef report(grid_scores, n_top=3):%0A    top_scores = sorted(grid_scores, key=itemgetter(1), reverse=True)%5B:n_top%5D%0A    for i, score in enumerate(top_scores):%0A        print(%22Model with rank: %7B0%7D%22.format(i + 1))%0A        print(%22Mean validation score: %7B0:.3f%7D (std: %7B1:.3f%7D)%22.format(%0A              score.mean_validation_score,%0A              np.std(score.cv_validation_scores)))%0A        print(%22Parameters: %7B0%7D%22.format(score.parameters))%0A        print(%22%22)%0A%0A%0A# specify parameters and distributions to sample from%0Aparam_dist = %7B%22max_depth%22: %5B3, None%5D,%0A              %22max_features%22: sp_randint(1, 11),%0A              %22min_samples_split%22: sp_randint(1, 11),%0A              %22min_samples_leaf%22: sp_randint(1, 11),%0A              %22bootstrap%22: %5BTrue, False%5D,%0A              %22criterion%22: %5B%22gini%22, %22entropy%22%5D%7D%0A%0A# run randomized search%0An_iter_search = 20%0Arandom_search = RandomizedSearchCV(clf, param_distributions=param_dist, n_iter=n_iter_search, n_jobs=2)%0Astart = time()%0Arandom_search.fit(X, y)%0Aprint(%22RandomizedSearchCV took %25.2f seconds for %25d candidates%22%0A      %22 parameter settings.%22 %25 ((time() - start), n_iter_search))%0A%0A# report(random_search.grid_scores_)%0Ainst = genfromtxt('instance.csv', delimiter=',')%0Aout = random_search.predict(inst%5B:, 1:%5D)%0As = np.vstack(%5Bmap(lambda x:(int(x)), inst%5B:, 0%5D), map(lambda x:(int(x)), out)%5D).T%0Apred = map(lambda x: %5Bstr(x%5B0%5D), str(x%5B1%5D)%5D, s)%0Anp.savetxt(%22pred.csv%22, pred, delimiter=%22,%22, fmt=%22%25s%22)%0A

Add Random Forest model.