plot_roc#

scikitplot.api.metrics.plot_roc(y_true, y_probas, *, pos_label=None, class_index=None, class_names=None, multi_class=None, to_plot_class_index=None, title='ROC AUC Curves', title_fontsize='large', text_fontsize='medium', cmap=None, show_labels=True, digits=4, plot_micro=True, plot_macro=False, **kwargs)[source]#

Generates the ROC AUC curves from labels and predicted scores/probabilities.

The ROC (Receiver Operating Characteristic) curve plots the true positive rate against the false positive rate at various threshold settings. The AUC (Area Under the Curve) represents the degree of separability achieved by the classifier. This function supports both binary and multiclass classification tasks.

Parameters:
y_truearray-like, shape (n_samples,)

Ground truth (correct) target values.

y_probasarray-like, shape (n_samples,) or (n_samples, n_classes)

Predicted probabilities for each class or only target class probabilities. If 1D, it is treated as probabilities for the positive class in binary or multiclass classification with the class_index.

class_nameslist of str, optional, default=None

List of class names for the legend. Order should match the order of classes in y_probas.

multi_class{‘ovr’, ‘multinomial’, None}, optional, default=None
Strategy for handling multiclass classification:
  • ‘ovr’: One-vs-Rest, plotting binary problems for each class.

  • ‘multinomial’ or None: Multinomial plot for the entire probability distribution.

class_indexint, optional, default=1

Index of the class of interest for multi-class classification. Ignored for binary classification.

to_plot_class_indexlist-like, optional, default=None

Specific classes to plot. If a given class does not exist, it will be ignored. If None, all classes are plotted.

titlestr, optional, default=’ROC AUC Curves’

Title of the generated plot.

title_fontsizestr or int, optional, default=’large’

Font size for the plot title.

text_fontsizestr or int, optional, default=’medium’

Font size for the text in the plot.

cmapNone, str or matplotlib.colors.Colormap, optional, default=None

Colormap used for plotting. Options include ‘viridis’, ‘PiYG’, ‘plasma’, ‘inferno’, ‘nipy_spectral’, etc. See Matplotlib Colormap documentation for available choices.

show_labelsbool, optional, default=True

Whether to display the legend labels.

digitsint, optional, default=3

Number of digits for formatting ROC AUC values in the plot.

Added in version 0.3.9.

plot_microbool, optional, default=False

Whether to plot the micro-average ROC AUC curve.

plot_macrobool, optional, default=False

Whether to plot the macro-average ROC AUC curve.

**kwargs: dict

Generic keyword arguments.

Returns:
matplotlib.axes.Axes

The axes with the plotted ROC AUC curves.

Other Parameters:
axmatplotlib.axes.Axes, optional, default=None

The axis to plot the figure on. If None is passed in the current axes will be used (or generated if required).

figmatplotlib.pyplot.figure, optional, default: None

The figure to plot the Visualizer on. If None is passed in the current plot will be used (or generated if required).

figsizetuple, optional, default=None

Width, height in inches. Tuple denoting figure size of the plot e.g. (12, 5)

nrowsint, optional, default=1

Number of rows in the subplot grid.

ncolsint, optional, default=1

Number of columns in the subplot grid.

plot_stylestr, optional, default=None

Check available styles with “plt.style.available”. Examples include: [‘ggplot’, ‘seaborn’, ‘bmh’, ‘classic’, ‘dark_background’, ‘fivethirtyeight’, ‘grayscale’, ‘seaborn-bright’, ‘seaborn-colorblind’, ‘seaborn-dark’, ‘seaborn-dark-palette’, ‘tableau-colorblind10’, ‘fast’].

Added in version 0.4.0.

show_figbool, default=True

Show the plot.

save_figbool, default=False

Save the plot.

save_fig_filenamestr, optional, default=’’

Specify the path and filetype to save the plot. If nothing specified, the plot will be saved as png inside result_images under to the current working directory. Defaults to plot image named to used func.__name__.

verbosebool, optional

If True, prints debugging information.

Notes

The implementation is specific to binary classification. For multiclass problems, the ‘ovr’ or ‘multinomial’ strategies can be used. When multi_class='ovr', the plot focuses on the specified class (class_index).

References#

Examples

>>> from sklearn.datasets import load_digits as data_10_classes
>>> from sklearn.model_selection import train_test_split
>>> from sklearn.naive_bayes import GaussianNB
>>> import scikitplot as skplt
>>> 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
... )
>>> model = GaussianNB()
>>> model.fit(X_train, y_train)
>>> y_probas = model.predict_proba(X_val)
>>> skplt.metrics.plot_roc(
>>>     y_val, y_probas,
>>> );

(Source code, png)

ROC AUC Curves