PrevalenceDisplay#

class mlquantify.visualization.PrevalenceDisplay(predicted_prevalence, *, true_prevalence=None, class_names=None, yerr=None)[source]#

Bar chart of a single sample’s predicted class prevalence.

For one test sample, draw the predicted prevalence of each class as a bar, optionally next to the true prevalence and/or with error bars (e.g. from a confidence interval). This is the natural way to inspect a single quantifier prediction, especially in the multiclass setting.

Parameters:
predicted_prevalencearray-like of shape (n_classes,) or dict

Predicted prevalence. Dicts are coerced using class_names ordering.

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

Optional ground-truth prevalence drawn alongside the prediction.

class_nameslist of str, default=None

Class labels in vector order. Inferred from dict keys when available.

yerrarray-like, default=None

Error-bar sizes for the predicted bars, in the format accepted by ax.bar(yerr=...) (shape (n_classes,) or (2, n_classes)).

Attributes:
bar_matplotlib BarContainer

The predicted-prevalence bars.

true_bar_matplotlib BarContainer or None

The true-prevalence bars (None when true_prevalence is not given).

ax_matplotlib Axes
figure_matplotlib Figure

See also

ConfidenceRegionDisplay

Uncertainty region for a single prediction.

Examples

>>> from mlquantify.visualization import PrevalenceDisplay
>>> disp = PrevalenceDisplay.from_predictions(   
...     [0.3, 0.7], true_prevalence=[0.4, 0.6], class_names=["neg", "pos"])
classmethod from_estimator(quantifier, X, *, true_prevalence=None, ax=None, name=None, **kwargs)[source]#

Predict on X with quantifier and plot the prevalence.

Parameters:
quantifierBaseQuantifier

A fitted quantifier exposing predict and classes_.

Xarray-like

The single test sample to quantify.

true_prevalencearray-like or dict, default=None

Optional ground truth to draw alongside.

axmatplotlib Axes, default=None
namestr, default=None

Legend label for the predicted bars.

**kwargs

Passed to plot.

Returns:
displayPrevalenceDisplay
classmethod from_predictions(predicted_prevalence, *, true_prevalence=None, class_names=None, yerr=None, ax=None, **kwargs)[source]#

Build a PrevalenceDisplay from a prevalence vector.

plot(ax=None, *, name=None, **kwargs)[source]#

Draw the prevalence bars.

Parameters:
axmatplotlib Axes, default=None

Axes to draw on.

namestr, default=None

Legend label for the predicted bars (defaults to "predicted").

**kwargs

Forwarded to the predicted-bar ax.bar call.

Returns:
displayPrevalenceDisplay