Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a threshold-coded ROC plot in Python

R's ROCR package provides options for ROC curve plotting that will color code and label threshold values along the curve:

The closest I can get with Python is something like

from sklearn.metrics import roc_curve
fpr, tpr, thresholds = roc_curve(qualityTrain.PoorCare, qualityTrain.Pred1)
plt.plot(fpr, tpr, label='ROC curve', color='b')
plt.axes().set_aspect('equal')
plt.xlim([-0.05, 1.05])
plt.ylim([-0.05, 1.05])

which gives

Are there packages that provide functionality equivalent to R's ability to label (using print.cutoffs.at) and color code (using colorize) thresholds? Presumably this information is in thresholds, returned by sklearn.metrics.roc_curve, but I can't figure out how to use it to color code and label the figure.

like image 735
orome Avatar asked Mar 19 '14 21:03

orome


1 Answers

Look at this gist:

https://gist.github.com/podshumok/c1d1c9394335d86255b8

roc_data = sklearn.metrics.roc_curve(...)
plot_roc(*roc_data, label_every=5)
like image 189
podshumok Avatar answered Sep 20 '22 21:09

podshumok