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

In this example we'll be generating a KS statistic plot with scikit-learn's LogisticRegression classifier to the breast cancer dataset. The scikitplot.metrics.plot_ks_statistic takes the ground-truth labels y_true and the predicted probabilities y_probas


In [1]:
from __future__ import absolute_import
import matplotlib.pyplot as plt
from sklearn.linear_model import LogisticRegression
from sklearn.datasets import load_breast_cancer 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
lr = LogisticRegression()

# Fit the model
lr.fit(X,y)
y_probas = lr.predict_proba(X)

In [3]:
# Plot!
skplt.metrics.plot_ks_statistic(y, y_probas)
plt.show()