-
-
Save saihttam/7241db5be80d076c1e8f to your computer and use it in GitHub Desktop.
Plot ROC Curve with Cut-Off Markers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment