BiasDisplay#

class mlquantify.visualization.BiasDisplay(true_prevalences, predicted_prevalences, *, class_names=None)[source]#

Boxplots of signed prevalence-estimation error.

Visualises the signed error predicted - true across the samples of an evaluation protocol. A box centred above zero reveals systematic over-estimation; below zero, under-estimation; a tall box reveals high variance. Two layouts are available:

  • global (default): one box per class.

  • binned: for a single class, one box per bin of the true prevalence, exposing how the bias changes along the prevalence range.

This is a multiple-sample display. It follows the boxplot convention used throughout the quantification literature for reporting estimation error (e.g. González et al., 2024).

Parameters:
true_prevalencesndarray of shape (n_samples, n_classes)

True prevalence of each evaluation sample.

predicted_prevalencesndarray of shape (n_samples, n_classes)

Predicted prevalence of each evaluation sample.

class_nameslist of str, default=None

Class labels in column order.

Attributes:
boxplot_dict

The dictionary returned by ax.boxplot.

hline_matplotlib Line2D

The horizontal zero-bias reference line.

ax_matplotlib Axes
figure_matplotlib Figure

See also

DiagonalDisplay

True vs. predicted prevalence scatter.

Examples

>>> from mlquantify.visualization import BiasDisplay
>>> from mlquantify.counting import CC
>>> from sklearn.linear_model import LogisticRegression
>>> from sklearn.datasets import make_classification
>>> X, y = make_classification(n_samples=400, random_state=0)
>>> disp = BiasDisplay.from_protocol(   
...     CC(LogisticRegression()), X, y, bins=5)
classmethod from_predictions(true_prevalences, predicted_prevalences, *, class_names=None, ax=None, **kwargs)[source]#

Build a BiasDisplay from precomputed prevalence arrays.

classmethod from_protocol(quantifier, X, y, *, protocol='app', ax=None, bins=None, class_index=None, name=None, **protocol_kwargs)[source]#

Run an evaluation protocol and plot the resulting bias boxplots.

Wrapper around mlquantify.model_selection.apply_protocol; **protocol_kwargs are forwarded to it.

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

Draw the bias boxplots.

Parameters:
axmatplotlib Axes, default=None

Axes to draw on.

binsint, default=None

If given, draw the binned layout: the chosen class’s samples are grouped into bins equal-width bins of true prevalence. If None, draw one box per class (global layout).

class_indexint, default=None

Class column used by the binned layout. Defaults to the last class (the conventional “positive” class).

namestr, default=None

Unused label kept for API symmetry; reserved for future legends.

**kwargs

Forwarded to ax.boxplot.

Returns:
displayBiasDisplay