# Path: autoencoder/testing/regression.py
# def neural_regression(X_train, Y_train, X_val, Y_val, X_test, Y_test, nb_epoch=200, batch_size=10, seed=7):
#     reg = neural_network(X_train.shape[1])
#     reg.fit(X_train, Y_train,
#                         nb_epoch=nb_epoch,
#                         batch_size=batch_size,
#                         shuffle=True,
#                         validation_data=(X_val, Y_val),
#                         callbacks=[
#                                     ReduceLROnPlateau(monitor='val_loss', factor=0.2, patience=3, min_lr=0.01),
#                                     EarlyStopping(monitor='val_loss', min_delta=1e-5, patience=5, verbose=0, mode='auto'),
#                         ]
#                         )
#     pred = reg.predict(X_test)
#     pred = np.reshape(pred, pred.shape[0])
#     r2 = r2_score(Y_test, pred)
# 
#     return r2
# 
# Path: autoencoder/utils/io_utils.py
# def load_json(file):
#     try:
#         with open(file, 'r') as datafile:
#             data = json.load(datafile)
#     except Exception as e:
#         raise e
# 
#     return data
# 
# def load_pickle(path_to_file):
#     try:
#         with open(path_to_file, 'r') as f:
#             data = pickle.load(f)
#     except Exception as e:
#         raise e
# 
#     return data


import argparse
import numpy as np
    import pdb;pdb.set_trace()
from keras.utils import np_utils
from sklearn.model_selection import ShuffleSplit
from autoencoder.testing.regression import neural_regression
from autoencoder.utils.io_utils import load_json, load_pickle
    Y_train = load_pickle(args.train_doc_labels)
    X_test = np.array(load_pickle(args.test_doc_codes))
    Y_test = load_pickle(args.test_doc_labels)

    seed = 7
    np.random.seed(seed)
    if not args.cross_validation:
        val_idx = np.random.choice(range(X_train.shape[0]), args.n_val, replace=False)
        train_idx = list(set(range(X_train.shape[0])) - set(val_idx))
        X_new_train = X_train[train_idx]
        Y_new_train = Y_train[train_idx]
        X_new_val = X_train[val_idx]
        Y_new_val = Y_train[val_idx]
        print 'train: %s, val: %s, test: %s' % (X_new_train.shape[0], X_new_val.shape[0], X_test.shape[0])

        results = neural_regression(X_new_train, Y_new_train, X_new_val, Y_new_val, \
                X_test, Y_test, nb_epoch=args.n_epoch, batch_size=args.batch_size, seed=seed)
        print 'r2 score on test set: %s' % results
    else:
        X = np.concatenate((X_train, X_test), axis=0)
        Y = np.concatenate((Y_train, Y_test), axis=0)
        ss = ShuffleSplit(n_splits=int(args.cross_validation), test_size=X_test.shape[0], random_state=seed)
        results = []
        for train_idx, test_idx in ss.split(X):
            val_idx = np.random.choice(train_idx, args.n_val, replace=False)
            new_train_idx = list(set(train_idx) - set(val_idx))
            X_new_train = X[new_train_idx]
            Y_new_train = Y[new_train_idx]
            X_new_val = X[val_idx]
            Y_new_val = Y[val_idx]

# Path: autoencoder/testing/regression.py
# def neural_regression(X_train, Y_train, X_val, Y_val, X_test, Y_test, nb_epoch=200, batch_size=10, seed=7):
#     reg = neural_network(X_train.shape[1])
#     reg.fit(X_train, Y_train,
#                         nb_epoch=nb_epoch,
#                         batch_size=batch_size,
#                         shuffle=True,
#                         validation_data=(X_val, Y_val),
#                         callbacks=[
#                                     ReduceLROnPlateau(monitor='val_loss', factor=0.2, patience=3, min_lr=0.01),
#                                     EarlyStopping(monitor='val_loss', min_delta=1e-5, patience=5, verbose=0, mode='auto'),
#                         ]
#                         )
#     pred = reg.predict(X_test)
#     pred = np.reshape(pred, pred.shape[0])
#     r2 = r2_score(Y_test, pred)
# 
#     return r2
# 
# Path: autoencoder/utils/io_utils.py
# def load_json(file):
#     try:
#         with open(file, 'r') as datafile:
#             data = json.load(datafile)
#     except Exception as e:
#         raise e
# 
#     return data
# 
# def load_pickle(path_to_file):
#     try:
#         with open(path_to_file, 'r') as f:
#             data = pickle.load(f)
#     except Exception as e:
#         raise e
# 
#     return data


# Path: run_regression.py
import argparse
import numpy as np
    import pdb;pdb.set_trace()
from keras.utils import np_utils
from sklearn.model_selection import ShuffleSplit
from autoencoder.testing.regression import neural_regression
from autoencoder.utils.io_utils import load_json, load_pickle

    Y_train = load_pickle(args.train_doc_labels)
    X_test = np.array(load_pickle(args.test_doc_codes))
    Y_test = load_pickle(args.test_doc_labels)

    seed = 7
    np.random.seed(seed)
    if not args.cross_validation:
        val_idx = np.random.choice(range(X_train.shape[0]), args.n_val, replace=False)
        train_idx = list(set(range(X_train.shape[0])) - set(val_idx))
        X_new_train = X_train[train_idx]
        Y_new_train = Y_train[train_idx]
        X_new_val = X_train[val_idx]
        Y_new_val = Y_train[val_idx]
        print 'train: %s, val: %s, test: %s' % (X_new_train.shape[0], X_new_val.shape[0], X_test.shape[0])

        results = neural_regression(X_new_train, Y_new_train, X_new_val, Y_new_val, \
                X_test, Y_test, nb_epoch=args.n_epoch, batch_size=args.batch_size, seed=seed)
        print 'r2 score on test set: %s' % results
    else:
        X = np.concatenate((X_train, X_test), axis=0)
        Y = np.concatenate((Y_train, Y_test), axis=0)
        ss = ShuffleSplit(n_splits=int(args.cross_validation), test_size=X_test.shape[0], random_state=seed)
        results = []
        for train_idx, test_idx in ss.split(X):
            val_idx = np.random.choice(train_idx, args.n_val, replace=False)
            new_train_idx = list(set(train_idx) - set(val_idx))
            X_new_train = X[new_train_idx]
            Y_new_train = Y[new_train_idx]
            X_new_val = X[val_idx]
            Y_new_val = Y[val_idx]

            results.append(neural_regression(X_new_train, Y_new_train, X_new_val, Y_new_val, \