import numpy as np
from sklearn.ensemble import AdaBoostClassifier
from sklearn.cross_validation import (StratifiedKFold, LeaveOneOut,
                                      cross_val_score)
from sklearn.grid_search import GridSearchCV
# from sklearn.pipeline import make_pipeline

from my_settings import *

subjects = ["0008", "0009", "0010", "0012", "0013", "0014", "0015", "0016",
            "0017", "0018", "0019", "0020", "0021", "0022"]

for subject in subjects:
    cls = np.load(source_folder + "graph_data/%s_classic_pow_pln.npy" %
                  subject).item()
    pln = np.load(source_folder + "graph_data/%s_plan_pow_pln.npy" %
                  subject).item()

results_all = {}

for band in bands:
    results_cls = []
    results_pln = []
    results_cls.append(cls[band].mean(axis=0))
    results_pln.append(pln[band].mean(axis=0))

    idx = np.tril_indices_from(results_cls[0], k=-1)

    data_cls = []
    data_pln = []

    for j in range(len(results_cls)):
        data_cls += [results_cls[j][idx]]
        data_pln += [results_pln[j][idx]]

    data_cls = np.asarray(data_cls)
    data_pln = np.asarray(data_pln)

    X = np.vstack([data_cls, data_pln])
    y = np.concatenate([np.zeros(len(data_cls)), np.ones(len(data_pln))])

    cv = StratifiedKFold(y, n_folds=10)
    llo = LeaveOneOut(len(y))

    ada = AdaBoostClassifier()

    adaboost_params = {"n_estimators": np.arange(20, 500, 20),
                       "learning_rate": np.arange(0.1, 1.1, 0.1)}

    grid = GridSearchCV(ada,
                        param_grid=adaboost_params,
                        cv=cv,
                        verbose=2,
                        n_jobs=6)
    grid.fit(X, y

    ada_cv = grid.best_estimator_

    scores = cross_val_score(ada_cv, X, y, cv=cv, scoring="roc_auc")

    results_all["%s_scores" % band] = scores
    results_all["%s_best_est" % band] = ada_cv

@@ -438,16 +438,39 @@
 0022%22%5D%0A%0A
+for band in bands:%0A    
 for subj
@@ -486,16 +486,20 @@
 bjects:%0A
+    
     cls 
@@ -572,32 +572,36 @@
                 
+   
+ 
 subject).item()%0A
@@ -600,16 +600,20 @@
 .item()%0A
+    
     pln 
@@ -683,32 +683,36 @@
                 
+    
 subject).item()%0A
@@ -712,16 +712,24 @@
 item()%0A%0A
+        
 results_
@@ -738,35 +738,20 @@
 l = %7B%7D%0A%0A
-for band in bands:%0A
+    
     resu
@@ -759,32 +759,36 @@
 ts_cls = %5B%5D%0A    
+   
+ 
 results_pln = %5B%5D
@@ -784,24 +784,28 @@
 ts_pln = %5B%5D%0A
+    
     results_
@@ -839,24 +839,28 @@
 xis=0))%0A    
+  
+  
 results_pln.
@@ -887,24 +887,28 @@
 n(axis=0))%0A%0A
+    
     idx = np
@@ -949,24 +949,28 @@
  k=-1)%0A%0A    
+  
+  
 data_cls = %5B
@@ -971,24 +971,28 @@
 ls = %5B%5D%0A    
+  
+  
 data_pln = %5B
@@ -994,24 +994,28 @@
 n = %5B%5D%0A%0A    
+ 
+   
 for j in ran
@@ -1036,16 +1036,20 @@
 _cls)):%0A
+    
         
@@ -1082,32 +1082,36 @@
 %5D%5Bidx%5D%5D%0A        
+ 
+   
 data_pln += %5Bres
@@ -1129,16 +1129,20 @@
 %5Bidx%5D%5D%0A%0A
+    
     data
@@ -1169,16 +1169,20 @@
 ta_cls)%0A
+    
     data
@@ -1214,16 +1214,20 @@
 n)%0A%0A    
+   
+ 
 X = np.v
@@ -1254,16 +1254,20 @@
 a_pln%5D)%0A
+    
     y = 
@@ -1337,16 +1337,20 @@
 %5D)%0A%0A    
+  
+  
 cv = Str
@@ -1377,16 +1377,20 @@
 lds=10)%0A
+    
     llo 
@@ -1416,16 +1416,20 @@
 ))%0A%0A    
+  
+  
 ada = Ad
@@ -1444,24 +1444,28 @@
 assifier()%0A%0A
+    
     adaboost
@@ -1538,16 +1538,20 @@
         
+ 
+   
 %22learnin
@@ -1586,16 +1586,20 @@
  0.1)%7D%0A%0A
+    
     grid
@@ -1643,16 +1643,20 @@
         
+ 
+   
 param_gr
@@ -1675,16 +1675,20 @@
 params,%0A
+    
         
@@ -1734,16 +1734,20 @@
         
+    
 verbose=
@@ -1749,16 +1749,20 @@
 bose=2,%0A
+    
         
@@ -1787,16 +1787,20 @@
 jobs=6)%0A
+    
     grid
@@ -1808,22 +1808,27 @@
 fit(X, y
+)
 %0A%0A    
+  
+  
 ada_cv =
@@ -1850,16 +1850,20 @@
 mator_%0A%0A
+    
     scor
@@ -1924,24 +1924,28 @@
 _auc%22)%0A%0A    
+ 
+   
 results_all%5B
@@ -1973,16 +1973,20 @@
  scores%0A
+    
     resu
@@ -2024,8 +2024,67 @@
  ada_cv%0A
+%0Anp.save(source_folder + %22graph_data/adaboost_reuslt.npy%22)%0A

change structure of loops