[{'role': 'system', 'content': "You are an expert in machine learning and your task is to classify code snippets into one of the following categories: ['helper_functions', 'load_data', 'data_exploration', 'data_preprocessing', 'evaluation', 'modelling', 'prediction', 'result_visualization', 'save_results', 'comment_only']."}, {'role': 'user', 'content': 'Identify the single most appropriate category to which the provided code belongs. Provide your response as a single category label without any additional information, commentary, or personal opinions.\\nPython Code:import pandas as pd<br>import numpy as np<br>from scipy import sparse as ssp<br>import pylab as plt<br>from sklearn.preprocessing import LabelEncoder,LabelBinarizer,MinMaxScaler,OneHotEncoder<br>from sklearn.feature_extraction.text import TfidfVectorizer,CountVectorizer<br>from sklearn.decomposition import TruncatedSVD,NMF,PCA,FactorAnalysis<br>from sklearn.feature_selection import SelectFromModel,SelectPercentile,f_classif<br>from sklearn.decomposition import TruncatedSVD<br>from sklearn.metrics import log_loss,roc_auc_score<br>from sklearn.pipeline import Pipeline,make_pipeline<br>from sklearn.cross_validation import StratifiedKFold,KFold<br>from keras.preprocessing import sequence<br>from keras.callbacks import ModelCheckpoint,Callback<br>from keras import backend as K<br>from keras.layers import Input, Embedding, LSTM, Dense,Flatten, Dropout, merge,Convolution1D,MaxPooling1D,Lambda,AveragePooling1D,Reshape<br>from keras.layers.normalization import BatchNormalization<br>from keras.optimizers import SGD<br>from keras.layers.advanced_activations import PReLU,LeakyReLU,ELU,SReLU<br>from keras.models import Model<br><br>seed = 1<br>np.random.seed(seed)<br>dim = 32<br>hidden=64<br><br>path = "../input/"<br><br>class AucCallback(Callback):  #inherits from Callback<br>    <br>    def __init__(self, validation_data=(), patience=25,is_regression=True,best_model_name=\'best_keras.mdl\',feval=\'roc_auc_score\',batch_size=1024*8):<br>        super(Callback, self).__init__()<br>        <br>        self.patience = patience<br>        self.X_val, self.y_val = validation_data  #tuple of validation X and y<br>        self.best = -np.inf<br>        self.wait = 0  #counter for patience<br>        self.best_model=None<br>        self.best_model_name = best_model_name<br>        self.is_regression = is_regression<br>        self.y_val = self.y_val#.astype(np.int)<br>        self.feval = feval<br>        self.batch_size = batch_size<br>    def on_epoch_end(self, epoch, logs={}):<br>        p = self.model.predict(self.X_val,batch_size=self.batch_size, verbose=0)#.ravel()<br>        if self.feval==\'roc_auc_score\':<br>            current = roc_auc_score(self.y_val,p)<br><br>        if current > self.best:<br>            self.best = current<br>            self.wait = 0<br>            self.model.save_weights(self.best_model_name,overwrite=True)<br>            <br><br>        else:<br>            if self.wait >= self.patience:<br>                self.model.stop_training = True<br>                print(\'Epoch %05d: early stopping\' % (epoch))<br>                <br>                <br>            self.wait += 1 #incremental the number of times without improvement<br>        print(\'Epoch %d Auc: %f | Best Auc: %f \\<br>\' % (epoch,current,self.best))<br><br><br>def make_batches(size, batch_size):<br>    nb_batch = int(np.ceil(size/float(batch_size)))<br>    return [(i*batch_size, min(size, (i+1)*batch_size)) for i in range(0, nb_batch)]<br><br><br><br>def main():<br>    train = pd.read_csv(path+\'act_train.csv\')<br>    test = pd.read_csv(path+\'act_test.csv\')<br>    people = pd.read_csv(path+\'people.csv\')<br>    columns = people.columns<br>    test[\'outcome\'] = np.nan<br>    data = pd.concat([train,test])<br>    <br>    data = pd.merge(data,people,how=\'left\',on=\'people_id\').fillna(\'missing\')<br>    train = data[:train.shape[0]]<br>    test = data[train.shape[0]:]<br><br><br><br>    columns = train.columns.tolist()<br>    columns.remove(\'activity_id\')<br>    columns.remove(\'outcome\')<br>    data = pd.concat([train,test])<br>    for c in columns:<br>        data[c] = LabelEncoder().fit_transform(data[c].values)<br><br>    train = data[:train.shape[0]]<br>    test = data[train.shape[0]:]<br>    <br>    data = pd.concat([train,test])<br>    columns = train.columns.tolist()<br>    columns.remove(\'activity_id\')<br>    columns.remove(\'outcome\')<br>    flatten_layers = []<br>    inputs = []<br>    count=0<br>    for c in columns:<br>        <br>        inputs_c = Input(shape=(1,), dtype=\'int32\')<br><br>        num_c = len(np.unique(data[c].values))<br><br>        embed_c = Embedding(<br>                        num_c,<br>                        dim,<br>                        dropout=0.2,<br>                        input_length=1<br>                        )(inputs_c)<br>        flatten_c= Flatten()(embed_c)<br><br>        inputs.append(inputs_c)<br>        flatten_layers.append(flatten_c)<br>        count+=1<br><br>    flatten = merge(flatten_layers,mode=\'concat\')<br>    reshaped_flatten = Reshape((count,dim))(flatten)<br>    <br>    conv_1 = Convolution1D(nb_filter=16,<br>                        filter_length=3,<br>                        border_mode=\'same\',<br>                        activation=\'relu\',<br>                        subsample_length=1)(reshaped_flatten)<br>    pool_1 = MaxPooling1D(pool_length=int(count/2))(conv_1)<br>    <br>    flatten = Flatten()(pool_1)<br>    <br>    <br>    fc1 = Dense(hidden,activation=\'relu\')(flatten)<br>    dp1 = Dropout(0.5)(fc1)<br><br>    outputs = Dense(1,activation=\'sigmoid\')(dp1)<br><br>    model = Model(input=inputs, output=outputs)<br>    model.compile(<br>                optimizer=\'adam\',<br>                loss=\'binary_crossentropy\',<br>              )<br><br>    del data<br><br>    X = train[columns].values<br>    X_t = test[columns].values<br>    y = train["outcome"].values<br>    people_id = train["people_id"].values<br>    activity_id = test[\'activity_id\']<br>    del train<br>    del test<br><br>    skf = StratifiedKFold(y, n_folds=4, shuffle=True, random_state=seed)<br>    for ind_tr, ind_te in skf:<br>        X_train = X[ind_tr]<br>        X_test = X[ind_te]<br><br>        y_train = y[ind_tr]<br>        y_test = y[ind_te]<br>        break<br>    <br>    X_train = [X_train[:,i] for i in range(X.shape[1])]<br>    X_test = [X_test[:,i] for i in range(X.shape[1])]<br>    <br>    del X<br><br>    model_name = \'mlp_residual_%s_%s.hdf5\'%(dim,hidden)<br>    model_checkpoint = ModelCheckpoint(model_name, monitor=\'val_loss\', save_best_only=True)<br>    auc_callback = AucCallback(validation_data=(X_test,y_test), patience=5,is_regression=True,best_model_name=path+\'best_keras.mdl\',feval=\'roc_auc_score\')<br>    <br>    nb_epoch = 2<br><br>    batch_size = 1024*8<br>    load_model = False<br>    <br>    if load_model:<br>        print(\'Load Model\')<br>        model.load_weights(path+model_name)<br>        # model.load_weights(path+\'best_keras.mdl\')<br><br>    model.fit(<br>        X_train, <br>        y_train,<br>        batch_size=batch_size, <br>        nb_epoch=nb_epoch, <br>        verbose=1, <br>        shuffle=True,<br>        validation_data=[X_test,y_test],<br>        # callbacks = [<br>            # model_checkpoint,<br>            # auc_callback,<br>            # ],<br>        )<br>    <br>    # model.load_weights(model_name)<br>    # model.load_weights(path+\'best_keras.mdl\')<br>    <br>    y_preds = model.predict(X_test,batch_size=1024*8)<br>    # print(\'auc\',roc_auc_score(y_test,y_preds))<br>    <br>    # print(\'Make submission\')<br>    X_t = [X_t[:,i] for i in range(X_t.shape[1])]<br>    outcome = model.predict(X_t,batch_size=1024*8)<br>    submission = pd.DataFrame()<br>    submission[\'activity_id\'] = activity_id<br>    submission[\'outcome\'] = outcome<br>    submission.to_csv(\'submission_residual_%s_%s.csv\'%(dim,hidden),index=False)<br><br>main()<br>'}, {'role': 'assistant', 'content': 'load_data'}]