from joblib import Parallel, delayed
from sklearn import cross_validation
from sklearn.grid_search import GridSearchCV
from sknn.mlp import Classifier, Layer

import data_util as util
import matplotlib.pyplot as plt
import numpy as np

bc_data_train, bc_data_test, bc_target_train, bc_target_test = util.load_breast_cancer()
v_data_train, v_data_test, v_target_train, v_target_test = util.load_vowel()

PORTIONS = np.arange(.1, 1.1, .1)
ITERATIONS = np.arange(250, 20250, 250)

def ann_n_iter():
    print "n_iter"
    print "---bc---"
    Parallel(n_jobs=-1)(
        delayed(_ann_n_iter)(
            bc_data_train,
            bc_data_test,
            bc_target_train,
            bc_target_test,
            n_iter) for n_iter in ITERATIONS)
    print "---v---"
    Parallel(n_jobs=-1)(
        delayed(_ann_n_iter)(
            v_data_train,
            v_data_test,
            v_target_train,
            v_target_test,
            n_iter) for n_iter in ITERATIONS)


def _ann_n_iter(data, data_test, target, target_test, n_iter):
    nn = Classifier(
        layers=[
            Layer("Sigmoid", units=100),
            Layer("Softmax")],
        n_iter=n_iter)
    train_score = np.mean(cross_validation.cross_val_score(nn, data, target, cv=10))
    nn.fit(data, target)
    test_score = nn.score(data_test, target_test)
    print n_iter, train_score, test_score


def ann_train_size():
    print "train_size"
    print "---bc---"
    Parallel(n_jobs=-1)(
        delayed(_ann_train_size)(
            bc_data_train,
            bc_data_test,
            bc_target_train,
            bc_target_test,
            train_size) for train_size in PORTIONS)
    print "---v---"
    Parallel(n_jobs=-1)(
        delayed(_ann_train_size)(
            v_data_train,
            v_data_test,
            v_target_train,
            v_target_test,
            train_size) for train_size in PORTIONS)


def _ann_train_size(data, data_test, target, target_test, train_size):
    nn = Classifier(
        layers=[
            Layer("Sigmoid", units=100),
            Layer("Softmax")])
    if train_size < 1:
        X_train, _, y_train, _ = cross_validation.train_test_split(
            data, target, train_size=train_size, stratify=target)
    else:
        X_train, y_train = data, target
    train_score = np.mean(cross_validation.cross_val_score(nn, X_train, y_train, cv=10))
    nn.fit(X_train, y_train)
    test_score = nn.score(data_test, target_test)
    print train_size, train_score, test_score

if __name__ == "__main__":
    ann_train_size()
    ann_n_iter()

@@ -435,32 +435,80 @@
 1)%0AITERATIONS = 
+%5B1, 5, 10, 50, 100, 150, 200%5D%0AITERATIONS.extend(
 np.arange(250, 2
@@ -517,16 +517,17 @@
 50, 250)
+)
 %0A%0Adef an
@@ -563,34 +563,33 @@
 %22%0A    print %22---
-bc
+v
 ---%22%0A    Paralle
@@ -636,34 +636,33 @@
 r)(%0A            
-bc
+v
 _data_train,%0A   
@@ -662,34 +662,33 @@
 in,%0A            
-bc
+v
 _data_test,%0A    
@@ -687,34 +687,33 @@
 st,%0A            
-bc
+v
 _target_train,%0A 
@@ -715,34 +715,33 @@
 in,%0A            
-bc
+v
 _target_test,%0A  
@@ -778,24 +778,41 @@
 n ITERATIONS
+ if n_iter %3C 2500
 )%0A    print 
@@ -807,33 +807,34 @@
 )%0A    print %22---
-v
+bc
 ---%22%0A    Paralle
@@ -881,33 +881,34 @@
 r)(%0A            
-v
+bc
 _data_train,%0A   
@@ -908,33 +908,34 @@
 in,%0A            
-v
+bc
 _data_test,%0A    
@@ -934,33 +934,34 @@
 st,%0A            
-v
+bc
 _target_train,%0A 
@@ -963,33 +963,34 @@
 in,%0A            
-v
+bc
 _target_test,%0A  
@@ -1480,16 +1480,253 @@
 n_size%22%0A
+    print %22---v---%22%0A    Parallel(n_jobs=-1)(%0A        delayed(_ann_train_size)(%0A            v_data_train,%0A            v_data_test,%0A            v_target_train,%0A            v_target_test,%0A            train_size) for train_size in PORTIONS)%0A
     prin
@@ -1963,245 +1963,8 @@
 NS)%0A
-    print %22---v---%22%0A    Parallel(n_jobs=-1)(%0A        delayed(_ann_train_size)(%0A            v_data_train,%0A            v_data_test,%0A            v_target_train,%0A            v_target_test,%0A            train_size) for train_size in PORTIONS)%0A
 %0A%0Ade
@@ -2357,103 +2357,59 @@
     
-train_score = np.mean(cross_validation.cross_val_score(nn, X_train, y_train, cv=10))%0A    nn.fit
+nn.fit(X_train, y_train)%0A    train_score = nn.score
 (X_t

Rearrange ann