Skip to content

Instantly share code, notes, and snippets.

@saihttam
Forked from anonymous/gist:1c6198cd663165d2dd53
Created September 27, 2015 16:45
Show Gist options
  • Save saihttam/7241db5be80d076c1e8f to your computer and use it in GitHub Desktop.
Save saihttam/7241db5be80d076c1e8f to your computer and use it in GitHub Desktop.

Revisions

  1. @invalid-email-address Anonymous created this gist Sep 7, 2015.
    19 changes: 19 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    def plot_roc(y, probs, threshmarkers=None):
    fpr, tpr, thresh = sklearn.metrics.roc_curve(y, probs)

    plt.plot(fpr, tpr, lw=2)
    if threshmarkers is None:
    threshmarkers = np.linspace(0, 1, 11)
    for t in threshmarkers:
    k = np.abs(thresh-t).argmin()
    x = fpr[k]
    y = tpr[k]
    plt.scatter(x, y, c="red", marker="x", s=50, lw=2, alpha=1.0)
    plt.annotate("%0.2f (%0.4f, %0.4f)" % (t, x, y), (x, y), textcoords="offset points", xytext=(25, -10), ha="left", va="center", fontsize=7, arrowprops={"arrowstyle":"->", "connectionstyle":"arc3,rad=0"})
    plt.xlabel("False Positive Rate\n(1 - Specificity)")
    plt.ylabel("True Positive Rate\n(Sensitivity)")
    plt.xlim([-0.025, 1.025])
    plt.ylim([-0.025, 1.025])
    plt.xticks(np.linspace(0, 1, 21), rotation=45)
    plt.yticks(np.linspace(0, 1, 21))
    plt.show()