plots.plot_conformal_by_true_class

plots.plot_conformal_by_true_class(
    calibration_scores,
    probs_test,
    y_test,
    alphas=None,
    cutoff_confidence=None,
    mondrian=False,
    y_calib=None,
    class_names=None,
)

Plot conformal prediction outcomes as small multiples, one panel per true class.

Each panel shows the distribution of prediction outcomes (correct, incorrect, two-set, empty) normalized within that class. This provides a detailed view of how conformal prediction performs for each class separately.

Parameters

calibration_scores : array-like of shape (n_calib,)

Nonconformity scores from the calibration set.

probs_test : array-like of shape (n_test, 2)

Predicted probabilities for the test set. Must be binary classification.

y_test : array-like of shape (n_test,)

True labels for the test set.

alphas : array - like = None

Alpha values to evaluate. Defaults to np.arange(0.01, 1.0, 0.01).

cutoff_confidence : float = None

If provided, draws a vertical line at this confidence level.

mondrian : bool = False

If True, compute per-class quantiles (Mondrian conformal prediction).

y_calib : array - like = None

Calibration labels. Required if mondrian=True.

class_names : tuple of str = None

Names for class 0 and class 1. Defaults to (“Class 0”, “Class 1”).

Returns

fig : matplotlib.figure.Figure

The figure object.

axes : array of matplotlib.axes.Axes

Array of axes objects (one per class).

Raises

: ValueError

If probs_test is not for binary classification or if mondrian=True but y_calib is not provided.

Notes

Unlike plot_conformal_coverage_by_class which shows all classes in one stacked plot, this function creates separate panels for each class, making it easier to compare within-class behavior.