plot_roc_curve with examples#

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

# Authors: The scikit-plots developers
# SPDX-License-Identifier: BSD-3-Clause

import numpy as np
from sklearn.datasets import (
    load_digits as data_10_classes,
)
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split

np.random.seed(0)  # reproducibility
# importing pylab or pyplot
import matplotlib.pyplot as plt

# Import scikit-plot
import scikitplot as sp

# Load the data
X, y = data_10_classes(return_X_y=True, as_frame=False)
X_train, X_val, y_train, y_val = train_test_split(X, y, test_size=0.5, random_state=0)

# Create an instance of the LogisticRegression
model = LogisticRegression(max_iter=int(1e5), random_state=0).fit(X_train, y_train)

# Perform predictions
y_val_prob = model.predict_proba(X_val)

# Plot!
ax = sp.metrics.plot_roc(y_val, y_val_prob)

# Adjust layout to make sure everything fits
plt.tight_layout()

# Save the plot with a filename based on the current script's name
# sp.api._utils.save_plot()

# Display the plot
plt.show(block=True)
ROC AUC Curves

Tags: model-type: classification model-workflow: model evaluation plot-type: line plot-type: roc-auc curve level: beginner purpose: showcase

Total running time of the script: (0 minutes 5.454 seconds)

Related examples

plot_roc_curve with examples

plot_roc_curve with examples

plot_confusion_matrix with examples

plot_confusion_matrix with examples

plot_silhouette with examples

plot_silhouette with examples

plot_classifier_eval with examples

plot_classifier_eval with examples

Gallery generated by Sphinx-Gallery