ConfidenceRegionDisplay#

class mlquantify.visualization.ConfidenceRegionDisplay(prev_estims, *, confidence_level=0.95, class_names=None, true_prevalence=None)[source]#

Confidence region around a single prevalence prediction.

Visualises the uncertainty of one quantifier prediction, obtained from a set of bootstrap prevalence estimates (see mlquantify.confidence). The layout adapts to the number of classes:

  • 3 classes (kind='ternary'): the bootstrap estimates are projected onto the 2-simplex and a confidence ellipse is drawn, together with the point estimate and (optionally) the true prevalence.

  • otherwise (kind='interval'): a per-class “forest” plot of the point estimate with a percentile confidence interval per class.

This is a single-sample display.

Parameters:
prev_estimsndarray of shape (m, n_classes)

m bootstrap prevalence estimates for one prediction.

confidence_levelfloat, default=0.95

Confidence level of the region.

class_nameslist of str, default=None

Class labels in column order.

true_prevalencearray-like of shape (n_classes,), default=None

Optional ground-truth prevalence to overlay.

Attributes:
point_estimate_ndarray of shape (n_classes,)

Mean of the bootstrap estimates.

ellipse_matplotlib Ellipse or None

The confidence ellipse (ternary layout only).

scatter_matplotlib PathCollection or None

The projected bootstrap cloud (ternary layout only).

errorbar_matplotlib ErrorbarContainer or None

The per-class intervals (interval layout only).

ax_matplotlib Axes
figure_matplotlib Figure

See also

mlquantify.confidence.construct_confidence_region

Builds the regions.

PrevalenceDisplay

Plain per-class prevalence bars.

Examples

>>> import numpy as np
>>> from mlquantify.visualization import ConfidenceRegionDisplay
>>> estims = np.random.dirichlet([8, 6, 6], size=300)
>>> disp = ConfidenceRegionDisplay.from_estimates(   
...     estims, confidence_level=0.95, class_names=["a", "b", "c"])
classmethod from_estimates(prev_estims, *, confidence_level=0.95, class_names=None, true_prevalence=None, ax=None, **kwargs)[source]#

Build a display directly from bootstrap prevalence estimates.

classmethod from_region(region, *, class_names=None, true_prevalence=None, ax=None, **kwargs)[source]#

Build a display from a fitted mlquantify.confidence region.

Parameters:
regionBaseConfidenceRegion

A region instance exposing prev_estims and confidence_level (e.g. the output of mlquantify.confidence.construct_confidence_region).

class_nameslist of str, default=None
true_prevalencearray-like, default=None
axmatplotlib Axes, default=None
**kwargs

Passed to plot.

Returns:
displayConfidenceRegionDisplay
plot(ax=None, *, kind='auto', name=None, **kwargs)[source]#

Draw the confidence region.

Parameters:
axmatplotlib Axes, default=None

Axes to draw on.

kind{‘auto’, ‘ternary’, ‘interval’}, default=’auto’

Layout. 'auto' selects 'ternary' for 3-class problems and 'interval' otherwise.

namestr, default=None

Label for the point estimate.

**kwargs

Forwarded to the primary artist (ax.scatter of the bootstrap cloud for ternary; ax.errorbar for the interval layout).

Returns:
displayConfidenceRegionDisplay