ROC Curve Plotter

  1. Import modules

    • Using sklearn to plot the ROC Curve
      1
      2
      3
      import numpy as np
      from sklearn.metrics import accuracy_score, confusion_matrix, roc_auc_score, roc_curve
      import matplotlib.pyplot as plt
  2. Plot curve

    • get the false positive rate, true positive rate and thresholds by inputting the passing coordinates.
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      # Get the require elements
      fpr, tpr, thresholds = roc_curve([0,1,0,1,0,1], [0.56, 0.61, 0.43, 0.78, 0.12, 0.47])

      # sketch the coordinates
      plt.scatter([0, 0, 1/3, 1/3, 2/3, 2/3, 0, 1], [1/3, 2/3, 2/3, 1, 1, 1, 0, 1])

      # plot the curve
      plt.plot(fpr, tpr)

      plt.xlabel('False Positive Rate')
      plt.ylabel('True Positive Rate')
      print(f'model 1 AUC score: {roc_auc_score([0,1,0,1,0,1], [0.56, 0.61, 0.43, 0.78, 0.12, 0.47])}')