plots.plot_singleton_confusion_matrix

plots.plot_singleton_confusion_matrix(
    prediction_sets,
    y_true,
    *,
    class_names=None,
    ax=None,
    cmap='Blues',
    show_percentages=True,
    show_composition=True,
    figsize=(12, 5),
    title=None,
)

Plot visualization of singleton prediction confusion matrix.

Creates a two-panel visualization: 1. Heatmap of the confusion matrix for singleton predictions 2. Stacked bar chart showing SC/SI composition

Parameters

prediction_sets : list of sets or lists

Conformal prediction sets, one per sample.

y_true : array-like of shape (n_samples,)

True binary labels (0 or 1).

class_names : dict = None

Mapping from class labels to names for display. E.g., {0: "approve", 1: "reject"}. If None, uses {0: "class_0", 1: "class_1"}.

ax : array of matplotlib.axes.Axes = None

If provided, must be an array of 2 axes to plot on. If None, creates a new figure with 2 subplots.

cmap : str = "Blues"

Colormap for the heatmap.

show_percentages : bool = True

If True, show percentages alongside counts in heatmap cells.

show_composition : bool = True

If True, include the second subplot showing SC/SI composition. If False, only plot the confusion matrix.

figsize : tuple = (12, 5)

Figure size if creating new figure.

title : str = None

Main title for the figure.

Returns

fig : matplotlib.figure.Figure

The figure object.

axes : array of matplotlib.axes.Axes

The axes objects.

See Also

conformalpy.outcomes.singleton_confusion_matrix : Compute the confusion matrix. conformalpy.outcomes.singleton_confusion_report : Text report.

Examples

>>> from conformalpy.plots import plot_singleton_confusion_matrix
>>> prediction_sets = [{0}, {1}, {0}, {1}, {0, 1}]
>>> y_true = [0, 0, 1, 1, 0]
>>> fig, axes = plot_singleton_confusion_matrix(
...     prediction_sets, y_true,
...     class_names={0: "approve", 1: "reject"}
... )