import matplotlib.pyplot as plt
import numpy as np
from sklearn.metrics import precision_recall_curve, average_precision_score
class_F = np.array([0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1])
proba_F = np.array([0.05, 0.05, 0.15, 0.15, 0.25, 0.25, 0.35, 0.35, 0.45, 0.45, 0.55, 0.55, 0.65, 0.85, 0.95])
class_G = np.array([0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1])
proba_G = np.array([0.05, 0.05, 0.15, 0.15, 0.25, 0.25, 0.25, 0.35, 0.35, 0.45, 0.55, 0.55, 0.65, 0.75, 0.95])
precision_F, recall_F, _ = precision_recall_curve(class_F, proba_F)
precision_G, recall_G, _ = precision_recall_curve(class_G, proba_G)
ap_F = average_precision_score(class_F, proba_F)
ap_G = average_precision_score(class_G, proba_G)
plt.title("Precision-Recall Graph")
plt.xlabel('Recall')
plt.ylabel('Precision')
plt.plot(recall_F, precision_F, 'b', label='Model F (AP = %0.2f)' % ap_F)
plt.plot(recall_G, precision_G, 'g', label='Model G (AP = %0.2f)' % ap_G)
plt.legend(loc='upper right')
plt.show()