mc_confusion_matrix#
- bayesflow.diagnostics.plots.mc_confusion_matrix(pred_models: Mapping[str, ndarray] | ndarray, true_models: Mapping[str, ndarray] | ndarray, model_names: Sequence[str] = None, figsize: tuple = (5, 5), label_fontsize: int = 16, title_fontsize: int = 18, value_fontsize: int = 10, tick_fontsize: int = 12, xtick_rotation: int = None, ytick_rotation: int = None, normalize: str | None = 'true', cmap: Colormap | str = None, title: bool = True, ax: Axes = None) Figure[source]#
Plots a confusion matrix for validating a neural network trained for Bayesian model comparison.
- Parameters:
- pred_modelsnp.ndarray of shape (num_datasets, num_models)
The predicted posterior model probabilities (PMPs) per data set.
- true_modelsnp.ndarray of shape (num_datasets, num_models)
The one-hot-encoded true model indices per data set.
- model_nameslist or None, optional, default: None
The model names for nice plot titles. Inferred if None.
- figsizetuple or None, optional, default: (5, 5)
The figure size passed to the
matplotlibconstructor. Inferred ifNone- label_fontsizeint, optional, default: 16
The font size of the y-label and y-label texts
- title_fontsizeint, optional, default: 18
The font size of the title text.
- value_fontsizeint, optional, default: 10
The font size of the text annotations and the colorbar tick labels.
- tick_fontsizeint, optional, default: 12
The font size of the axis label and model name texts.
- xtick_rotation: int, optional, default: None
Rotation of x-axis tick labels (helps with long model names).
- ytick_rotation: int, optional, default: None
Rotation of y-axis tick labels (helps with long model names).
- normalize{‘true’, ‘pred’, ‘all’} or None, optional, default: ‘true’
Passed to the confusion matrix. Normalizes the counts over the true (rows), predicted (columns) conditions, or the whole population, yielding values in
[0, 1]that are annotated as fractions (.2f). With the default'true'each row sums to 1, so the diagonal reads as the per-model classification accuracy. PassNoneto display raw integer counts instead.- cmapmatplotlib.colors.Colormap or str, optional, default: None
Colormap to be used for the cells. If a str, it should be the name of a registered colormap, e.g., ‘viridis’. Default colormap matches the BayesFlow defaults by ranging from white to red.
- titlebool, optional, default True
A flag for adding ‘Confusion Matrix’ above the matrix.
- axmatplotlib.axes.Axes, optional, default: None
An existing axis to draw into. If
None, a new figure and axis are created. When provided,figsizeis ignored and the parent figure is returned, enabling composition (e.g. side-by-side panels).
- Returns:
- figplt.Figure - the figure instance for optional saving