n=nclasses,
                                       normalized=normalize_class)

    print('-' * 20)
    print('\nMATTHEWS CORRELATION')
    print(matthews_corrcoef(test_y, test_yy))
    CM = confusion_matrix(test_y, test_yy, labels=[1, 0, -1])
    print('\nCONFUSION MATRIX')
    print(CM / CM.astype(np.float).sum(axis=1))
    print('\nCLASSIFICATION REPORT')
    print(classification_report(test_y, test_yy, labels=[1, 0, -1], target_names=['buy', 'hold', 'sell']))
    print('-' * 20)

    plt.plot(predicted)
    plt.title('Predict')
    plt.ylabel('class')
    plt.xlabel('bar')
    plt.legend(['buy', 'hold', 'sell'])
    plt.show()

    plt.plot(data_yy)
    plt.title('Saved predict')
    plt.ylabel('class')
    plt.xlabel('bar')
    plt.legend(['prediction'])
    plt.show()

    if run_type == 0:
        plot_history(history)

    # Train
    history = autoencoder.fit(
        x_data,
        x_data,
        epochs=epochs,
        batch_size=batch,
        validation_split=0.1,
        shuffle=True,
        # callbacks=[tb]
    )

    # Save weights
    autoencoder.save_weights(wgt_path + model_name + '.hdf5')
    encoder.save_weights(wgt_path + model_name + '_enc.hdf5')
    plot_history(history, acc='acc')

## Visual evaluation
# Number of examples = n^2
n = 10
test_z_mean, test_z_log_var, test_z = encoder.predict(x_data[-100:],
                                                      batch_size=batch)

# Save images of origin and decoded data
if action in ['train1', 'train2', 'predict']:

    def plot_data(fname, plot_data):
        figure = np.zeros((img_width * n, img_width * n, 3))
        plot_data = plot_data[-(n * n):]
        for idx in range(n):
            for jdx in range(n):
np.savetxt(file_yy, data_yy, fmt='%.2f', delimiter=',')
print("Predict saved:\n", file_yy)


#=============================================================================#
#       P L O T                                                               #
#=============================================================================#
# test_y_ = [np.argmax(x) for x in test_y]
# test_yy = [np.argmax(x) for x in model.predict(test_x).reshape(test_x.shape[0], nclasses)]

# true, test
print(classification_scores(data_yyy, data_yy, nclasses))

# plt.plot(predicted)
# plt.title('Predict')
# plt.ylabel('class')
# plt.xlabel('bar')
# plt.legend(['buy', 'hold', 'sell'])
# plt.show()

plt.plot(data_yy)
plt.title('Saved predict')
plt.ylabel('class')
plt.xlabel('bar')
plt.legend(['prediction'])
plt.show()

plot_history(history, acc='categorical_accuracy')