An example showing the plot_roc_curve method used by a scikit-learn classifier

In this example, we'll be plotting the ROC curve for our Naive Bayes classifier on the digits dataset. First, we're going to fit our model with the data, then obtain the predicted probabilities y_probas. Afterwhich, we can then pass the ground-truth values y and y_probas into scikitplot.metrics.plot_roc_curve method.


In [1]:
from __future__ import absolute_import
import matplotlib.pyplot as plt
from sklearn.naive_bayes import GaussianNB
from sklearn.datasets import load_digits as load_data

# Import scikit-plot
import scikitplot as skplt

%pylab inline
pylab.rcParams['figure.figsize'] = (14, 14)


Populating the interactive namespace from numpy and matplotlib

In [2]:
# Load the data
X, y = load_data(return_X_y=True)

# Create classifier instance then fit
nb = GaussianNB()
nb.fit(X,y)

# Get y_probabilities
y_probas = nb.predict_proba(X)

In [3]:
# Plot!
skplt.metrics.plot_roc_curve(y, y_probas, cmap='nipy_spectral')
plt.show()