from matplotlib import pyplot as plt
import seaborn as sn
import pandas as pd
from sklearn.metrics import confusion_matrix


# function to plot confusion matrix based on a prediction vector

def confusionMatrixPlot(predicted):

    # true labels of test data
    true = [1, 2, 1, 2, 2, 2, 1, 2, 2, 1, 2, 2, 2, 1, 1, 2, 2, 2, 1, 1, 2, 1, 1, 1, 2, 2, 1, 2, 2, 2, 2, 2, 1, 2, 2, 2, 1, 1, 2, 2, 2, 1, 2, 2, 1, 2, 2, 1, 2, 2, 2, 2, 2, 1, 2, 2, 2, 1, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 1, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 1, 2, 1, 2, 2, 1, 1, 1, 2, 2, 2, 2, 2, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 1, 2, 2, 2, 1, 2, 2, 1, 2, 2, 1, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 1, 2, 2, 2, 1, 2]
    array = confusion_matrix(true, predicted)
    df_cm = pd.DataFrame(array, ["ME", "Not-ME",],  ["ME", "Not-ME",])
    plt.figure(figsize=(10,7))
    sn.set(font_scale=1.4)  # for label size
    sn.heatmap(df_cm, annot=True, annot_kws={"size": 15}, fmt='g')  # font size
    plt.savefig('confusionMatrix')
    plt.show()
    recall = round(array[0][0]/float(array[0][0] + array[1][0]), 2)
    precision = round(array[0][0]/float(array[0][0] + array[0][1]), 2)
    print("Recall : " + str(recall))
    print("Precision : " + str(precision))
    print("F1-Score : " + str(round(2 * (precision * recall)/(precision + recall), 2)))
    return
