kdiagram.plot.evaluation.plot_polar_confusion_matrix_in

kdiagram.plot.evaluation.plot_polar_confusion_matrix_in(y_true, y_pred, class_labels=None, normalize=True, title='Polar Confusion Matrix', figsize=(8, 8), cmap='tab10', colors=None, show_grid=True, grid_props=None, mask_radius=False, acov='default', zero_at='N', clockwise=True, categories=None, savefig=None, dpi=300, kind='polar', ax=None)[source]

Plots a Polar Confusion Matrix for multiclass classification.

This function creates a grouped polar bar chart to visualize the performance of a multiclass classifier. Each angular sector represents a true class, and the bars within it show the distribution of the model’s predictions for that class.

Parameters:
y_truenp.ndarray

1D array of true class labels.

y_prednp.ndarray

1D array of predicted class labels from a model.

class_labelslist of str, optional

Display names for each of the classes. If not provided, generic names like 'Class 0' will be generated. The order must correspond to the sorted order of the labels in y_true and y_pred.

normalizebool, default=True

If True, the confusion matrix values are normalized across each true class (row) to show proportions. If False, raw counts are shown.

titlestr, default=”Polar Confusion Matrix”

The title for the plot.

figsizetuple of (float, float), default=(8, 8)

The figure size in inches.

cmapstr, default=’viridis’

The colormap used to assign a unique color to each predicted class bar.

show_gridbool, default=True

Toggle the visibility of the polar grid lines.

grid_propsdict, optional

Custom keyword arguments passed to the grid for styling.

mask_radiusbool, default=False

If True, hide the radial tick labels.

savefigstr, optional

The file path to save the plot. If None, the plot is displayed interactively.

dpiint, default=300

The resolution (dots per inch) for the saved figure.

kind{‘polar’, ‘cartesian’}, default=’polar’

Rendering mode selector. When set to 'polar' (default), the plot uses a Matplotlib polar projection and applies polar-specific options (acov, zero_at, clockwise) via internal helpers. When set to 'cartesian', the function delegates to a Cartesian renderer (through maybe_delegate_cartesian), keeping names/colors/figsize/grid behavior consistent while ignoring polar- only arguments (e.g., acov, zero_at, clockwise). The return value is always the Axes actually used.

axAxes, optional

The Matplotlib Axes object to use for plotting. If None, a new figure and axes will be created.

Returns
——-
axmatplotlib.axes.Axes

The Matplotlib Axes object containing the plot.

Parameters:
Return type:

Axes

See also

plot_polar_confusion_matrix

The companion plot for binary problems.

sklearn.metrics.confusion_matrix

The underlying scikit-learn function.

Notes

The confusion matrix, \(\mathbf{C}\), is a fundamental tool for evaluating a classifier. Each element \(C_{ij}\) contains the number of observations known to be in group \(i\) but predicted to be in group \(j\).

This function visualizes this matrix by dedicating an angular sector to each true class \(i\). Within that sector, a set of bars is drawn, where the height of the \(j\)-th bar corresponds to the value of \(C_{ij}\). This makes it easy to see how samples from a single true class are distributed among the predicted classes [1].

References

Examples

>>> import numpy as np
>>> from sklearn.datasets import make_classification
>>> from kdiagram.plot.evaluation import plot_polar_confusion_matrix_in
>>>
>>> # Generate synthetic multiclass data
>>> X, y_true = make_classification(
...     n_samples=1000,
...     n_features=20,
...     n_informative=10,
...     n_classes=4,
...     n_clusters_per_class=1,
...     flip_y=0.15,
...     random_state=42
... )
>>> # Simulate predictions with some common confusions
>>> y_pred = y_true.copy()
>>> # Confuse some 2s as 3s
>>> y_pred[np.where((y_true == 2) & (np.random.rand(1000) < 0.3))] = 3
>>>
>>> # Generate the plot
>>> ax = plot_polar_confusion_matrix_in(
...     y_true,
...     y_pred,
...     class_labels=["Class A", "Class B", "Class C", "Class D"],
...     title="Multiclass Polar Confusion Matrix"
... )