def predict_model(train_x,
                  train_y,
                  test_x,
                  test_y=None,
                  class_weights=None,
                  random_state=0):
    # Learn the KNN model
    params = {
        'layers': [[1000, 0.90], [100, 0.60]],
        'loss': 'categorical_crossentropy'
    }
    model = fp.PMC_NeuralNetwork_T1(train_x.shape[1],
                                    train_y.shape[1],
                                    params,
                                    bags=1)
    model.fit(train_x, train_y, test_x, test_y, batch_size=64, nb_epoch=20)

    # Predict on the test instances
    test_predicted = model.predict_proba(test_x)
    counter = 1
    if test_y is not None:
        print("...score = {:.5f}".format(
            fp.brier_score(test_y, test_predicted / counter, class_weights)))

    # Add more epochs
    for k in range(4):
        model.fit(train_x, train_y, test_x, test_y, batch_size=128)
        test_predicted = test_predicted + model.predict_proba(test_x)
        counter += 1
        if test_y is not None:
            print("...score = {:.5f}".format(
                fp.brier_score(test_y, test_predicted / counter,
                               class_weights)))

    test_predicted = test_predicted / counter

    return (test_predicted)
    'L2_XGB_vD1_0', 'L2_XGB_vB2_1', 'L2_NN_vD1_0', 'L2_XGB_vC2_0'
]

# Set weights
weights = np.ones(len(files_txt))

if validate:
    validated = np.zeros((16124, 20))
    for i, file_txt in enumerate(files_txt):
        validated = validated + fd.load_L1_train([file_txt]) * weights[i]
    validated = validated / np.sum(weights)

    all_train_y = fd.load_train_y([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
    all_train_y = all_train_y[np.isfinite(all_train_y.sum(1))]
    print("Final Submission local-CV score: {}".format(
        fp.brier_score(all_train_y, validated, class_weights)))

# Predict L3 test data
predicted = np.zeros((16600, 20))
for i, file_txt in enumerate(files_txt):
    predicted = predicted + fd.load_submissions([file_txt]) * weights[i]
predicted = predicted / np.sum(weights)

name_to_save = 'L3_WA_vD2'

# Save files
directory = '../final_submission/'
if not os.path.exists(directory):
    os.makedirs(directory)
# Submission
submission = pd.concat((pd.DataFrame(rows), pd.DataFrame(predicted)), axis=1)