kdiagram.plot.evaluation.plot_polar_confusion_multiclass¶
- kdiagram.plot.evaluation.plot_polar_confusion_multiclass(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)¶
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_true
np.ndarray 1D array of true class labels.
- y_pred
np.ndarray 1D array of predicted class labels from a model.
- class_labels
listofstr,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 iny_trueandy_pred.- normalizebool, default=True
If
True, the confusion matrix values are normalized across each true class (row) to show proportions. IfFalse, raw counts are shown.- title
str, default=”PolarConfusionMatrix” The title for the plot.
- figsize
tupleof(float,float), default=(8, 8) The figure size in inches.
- cmap
str, 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_props
dict,optional Custom keyword arguments passed to the grid for styling.
- mask_radiusbool, default=False
If
True, hide the radial tick labels.- savefig
str,optional The file path to save the plot. If
None, the plot is displayed interactively.- dpi
int, 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 (throughmaybe_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 theAxesactually used.- ax
Axes,optional The Matplotlib Axes object to use for plotting. If
None, a new figure and axes will be created.- Returns
- ——-
- ax
matplotlib.axes.Axes The Matplotlib Axes object containing the plot.
- y_true
- Parameters:
- Return type:
See also
plot_polar_confusion_matrixThe companion plot for binary problems.
sklearn.metrics.confusion_matrixThe 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" ... )