mc_confusion_matrix#

bayesflow.diagnostics.mc_confusion_matrix(pred_models: Mapping[str, ndarray] | ndarray, true_models: Mapping[str, ndarray] | ndarray, model_names: Sequence[str] = None, fig_size: 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, cmap: Colormap | str = None, title: bool = True) Figure[source]#

Plots a confusion matrix for validating a neural network trained for Bayesian model comparison.

Parameters:
pred_modelsnp.ndarray of shape (num_data_sets, num_models)

The predicted posterior model probabilities (PMPs) per data set.

true_modelsnp.ndarray of shape (num_data_sets, 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.

fig_sizetuple or None, optional, default: (5, 5)

The figure size passed to the matplotlib constructor. Inferred if None

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’}, default=None

Passed to confusion matrix. Normalizes confusion matrix over the true (rows), predicted (columns) conditions or all the population. If None, confusion matrix will not be normalized.

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.

Returns:
figplt.Figure - the figure instance for optional saving