Receiver Operating Characteristic (ROC) With Cross Validation
Receiver Operating Characteristic (ROC) With Cross Validation
Click here
to download the full example code or to run this example in your browser via Binder
ROC curves typically feature true positive rate on the Y axis, and false
positive rate on the X axis. This means that the top left corner of the plot
is
the “ideal” point - a false positive rate of zero, and a true positive rate of
one. This is not very realistic, but it does mean that a larger area un‐
der the
curve (AUC) is usually better.
This example shows the ROC response of different datasets, created from K-fold
cross-validation. Taking all of these curves, it is possible to cal‐
culate the
mean area under curve, and see the variance of the curve when the
training set is split into different subsets. This roughly shows how
the
classifier output is affected by changes in the training data, and how
different the splits generated by K-fold cross-validation are from one
another.
Note:
See also sklearn.metrics.roc_auc_score,
sklearn.model_selection.cross_val_score,
Receiver Operating Characteristic (ROC),
Toggle Menu
print(__doc__)
import numpy as np
# #############################################################################
iris = datasets.load_iris()
X = iris.data
y = iris.target
random_state = np.random.RandomState(0)
# #############################################################################
cv = StratifiedKFold(n_splits=6)
random_state=random_state)
tprs = []
aucs = []
fig, ax = plt.subplots()
classifier.fit(X[train], y[train])
interp_tpr[0] = 0.0
tprs.append(interp_tpr)
aucs.append(viz.roc_auc)
label='Chance', alpha=.8)
mean_tpr[-1] = 1.0
std_auc = np.std(aucs)
lw=2, alpha=.8)
ax.legend(loc="lower right")
plt.show()
Toggle Menu
Download Jupyter notebook: plot_roc_crossval.ipynb
Toggle Menu