<commit_before>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

ann_train_size()<commit_msg>Add main if<commit_after>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()
{'fraction_non_alphanumeric': 0.09814634146341464, 'fraction_numerical': 0.011707317073170732, 'mean_word_length': 2.5871238628411475, 'pattern_counts': {'":': 1, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5018684', 'n_tokens_mistral': 1812, 'n_tokens_neox': 1748, 'n_words': 358}