<commit_before>import argparse as ap
import gc
import jsonpickle
import numpy as pd
import os
import pandas as pd
import sys

from itertools import chain
from jsonpickle.ext import numpy as jsonpickle_numpy

from keras import callbacks
from keras.models import Sequential, load_model
from keras.layers import BatchNormalization, Dense, Dropout, PReLU
from keras.wrappers.scikit_learn import KerasClassifier

from tabulate import tabulate

from sklearn import preprocessing
from sklearn.externals import joblib
from sklearn.metrics import auc, precision_recall_fscore_support, roc_curve
from sklearn.model_selection import train_test_split
from sklearn.utils import shuffle


class Trainer(object):
    def __init__(self, **kwargs):
        if bool(kwargs):
            self.args = self.get_args(self.to_args_list(kwargs))

        else:
            self.args = self.get_args()

    def get_args(self, args=None):
        playdata = 'data/Xy.csv'

        parser = ap.ArgumentParser(description='Train wincast')

        parser.add_argument('--playdata', '-p', type=str, default=playdata)
        parser.add_argument('--nb-epoch', '-e', type=int, default=2)
        parser.add_argument('--verbose', '-v', default=False, action='store_true')
        parser.add_argument('--batch-size', '-b', type=int, default=128)
        parser.add_argument('--outdir', '-o', default=False)
        parser.add_argument('--indir', '-i', default=False)
        parser.add_argument('--monitor', '-m', action='store_true', default=False)
        parser.add_argument('--evaluate', action='store_true', default=False)
        parser.add_argument('--format', default='table', choices=('table', 'csv'))
        parser.add_argument('--headers', action='store_true', default=False)
        parser.add_argument('--board', action='store_true', default=False)

        return parser.parse_args(args=args)


    def to_args_list(self, args):
        args = [['--%s' % key, value] for key, value in args.items()]

        return chain.from_iterable(args)


    def create_baseline(self):

        # create model
        model = Sequential()

        model.add(Dense(30, input_dim=13, init='normal', activation='relu'))
        model.add(BatchNormalization())
        model.add(PReLU())
        model.add(Dropout(0.5))

        model.add(Dense(15, init='normal', activation='relu'))
        model.add(BatchNormalization())
        model.add(PReLU())
        model.add(Dropout(0.5))

        model.add(Dense(1, init='normal', activation='sigmoid'))

        # Compile model
        model.compile(loss='binary_crossentropy', optimizer='adam', metrics=[
            'accuracy', 'precision', 'recall'])

        return model


    def read(self):
        self.model = load_model(os.path.normpath(os.path.join(
            self.args.indir, 'wincast.model.h5')))
        self.scaler = joblib.load(os.path.normpath(os.path.join(
            self.args.indir, 'wincast.scaler.pkl')))


    def get_features(self, X):
        return X.loc[:, [
            'qtr',
            'min',
            'sec',
            'ptso',
            'ptsd',
            'timo',
            'timd',
            'dwn',
            'ytg',
            'yfog',
            'ou',
            'pts_s',
            'off_h',
        ]]


    def train(self):
        if self.args.indir:
            self.read()
            gc.collect()
            return

        self.scaler = preprocessing.StandardScaler()

        X = pd.read_csv(self.args.playdata) 
        X_train = X.loc[~X['seas'].isin([2000, 2007, 2015])] 
        X_test = X.loc[X['seas'].isin([2000, 2007, 2015])]

        y_train = X_train.loc[:, 'y']
        y_test = X_test.loc[:, 'y']
        <commit_msg>Use a deeper and wider architecture<commit_after>import argparse as ap
import gc
import jsonpickle
import numpy as pd
import os
import pandas as pd
import sys

from itertools import chain
from jsonpickle.ext import numpy as jsonpickle_numpy

from keras import callbacks
from keras.models import Sequential, load_model
from keras.layers import BatchNormalization, Dense, Dropout, PReLU
from keras.wrappers.scikit_learn import KerasClassifier

from tabulate import tabulate

from sklearn import preprocessing
from sklearn.externals import joblib
from sklearn.metrics import auc, precision_recall_fscore_support, roc_curve
from sklearn.model_selection import train_test_split
from sklearn.utils import shuffle


class Trainer(object):
    def __init__(self, **kwargs):
        if bool(kwargs):
            self.args = self.get_args(self.to_args_list(kwargs))

        else:
            self.args = self.get_args()

    def get_args(self, args=None):
        playdata = 'data/Xy.csv'

        parser = ap.ArgumentParser(description='Train wincast')

        parser.add_argument('--playdata', '-p', type=str, default=playdata)
        parser.add_argument('--nb-epoch', '-e', type=int, default=2)
        parser.add_argument('--verbose', '-v', default=False, action='store_true')
        parser.add_argument('--batch-size', '-b', type=int, default=128)
        parser.add_argument('--outdir', '-o', default=False)
        parser.add_argument('--indir', '-i', default=False)
        parser.add_argument('--monitor', '-m', action='store_true', default=False)
        parser.add_argument('--evaluate', action='store_true', default=False)
        parser.add_argument('--format', default='table', choices=('table', 'csv'))
        parser.add_argument('--headers', action='store_true', default=False)
        parser.add_argument('--board', action='store_true', default=False)

        return parser.parse_args(args=args)


    def to_args_list(self, args):
        args = [['--%s' % key, value] for key, value in args.items()]

        return chain.from_iterable(args)


    def create_baseline(self):

        # create model
        model = Sequential()

        model.add(Dense(64, input_dim=13, init='normal', activation='relu'))
        model.add(BatchNormalization())
        model.add(PReLU())
        model.add(Dropout(0.5))

        model.add(Dense(32, init='normal', activation='relu'))
        model.add(BatchNormalization())
        model.add(PReLU())
        model.add(Dropout(0.5))

        model.add(Dense(16, init='normal', activation='relu'))
        model.add(BatchNormalization())
        model.add(PReLU())
        model.add(Dropout(0.5))

        model.add(Dense(1, init='normal', activation='sigmoid'))

        # Compile model
        model.compile(loss='binary_crossentropy', optimizer='adam', metrics=[
            'accuracy', 'precision', 'recall'])

        return model


    def read(self):
        self.model = load_model(os.path.normpath(os.path.join(
            self.args.indir, 'wincast.model.h5')))
        self.scaler = joblib.load(os.path.normpath(os.path.join(
            self.args.indir, 'wincast.scaler.pkl')))


    def get_features(self, X):
        return X.loc[:, [
            'qtr',
            'min',
            'sec',
            'ptso',
            'ptsd',
            'timo',
            'timd',
            'dwn',
            'ytg',
            'yfog',
            'ou',
            'pts_s',
            'off_h',
        ]]


    def train(self):
        if self.args.indir:
            self.read()
            gc.collect()
            return

        self.scaler = preprocessing.StandardScaler()

        X = pd.read_csv(self.args.playdata) 
        X_train = X.loc[~X['seas'].isin([2001, 2008, 2016])] 
        X_test = X.loc[X['seas'].isin([2001, 2008, 2016])]

        y_train = X_train.loc[:, 'y']
        y_test = X_test.loc[:, 'y']
        
{'fraction_non_alphanumeric': 0.14059823428646726, 'fraction_numerical': 0.01106865199631045, 'mean_word_length': 2.59375, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2176142', 'n_tokens_mistral': 2490, 'n_tokens_neox': 2354, 'n_words': 483}