kdiagram.plot.evaluation.plot_polar_confusion_matrix

kdiagram.plot.evaluation.plot_polar_confusion_matrix(y_true, *y_preds, names=None, normalize=True, title='Polar Confusion Matrix', figsize=(8, 8), cmap='viridis', show_grid=True, grid_props=None, mask_radius=False, savefig=None, dpi=300)[source]

Plots a Polar Confusion Matrix for binary classification.

This function creates a polar bar chart to visualize the four key components of a binary confusion matrix: True Positives (TP), False Positives (FP), True Negatives (TN), and False Negatives (FN).

Parameters:
y_truenp.ndarray

1D array of true binary labels (0 or 1).

*y_predsnp.ndarray

One or more 1D arrays of predicted probabilities or scores for the positive class. A threshold of 0.5 is used to convert probabilities to class labels.

nameslist of str, optional

Display names for each of the models. If not provided, generic names like 'Model 1' will be generated.

normalizebool, default=True

If True, the confusion matrix values are normalized to proportions (summing to 1.0 for each model). 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 model’s set of bars.

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.

Returns:
axmatplotlib.axes.Axes

The Matplotlib Axes object containing the plot.

Parameters:

See also

plot_polar_confusion_multiclass

The companion plot for multiclass problems.

sklearn.metrics.confusion_matrix

The underlying scikit-learn function.

Notes

The confusion matrix is a fundamental tool for evaluating a classifier’s performance [1]. This function maps its four components to a polar bar chart for intuitive comparison.

  • True Positives (TP): Correctly predicted positive cases.

  • False Positives (FP): Negative cases incorrectly predicted as positive.

  • True Negatives (TN): Correctly predicted negative cases.

  • False Negatives (FN): Positive cases incorrectly predicted as negative.

Each of these four categories is assigned its own angular sector, and the height (radius) of the bar in that sector represents the count or proportion of samples in that category.

References

Examples

>>> import numpy as np
>>> from sklearn.datasets import make_classification
>>> from kdiagram.plot.evaluation import plot_polar_confusion_matrix
>>>
>>> # Generate synthetic binary classification data
>>> X, y_true = make_classification(
...     n_samples=500, n_classes=2, flip_y=0.2, random_state=42
... )
>>>
>>> # Simulate predictions from two models
>>> y_pred1 = y_true * 0.8 + np.random.rand(500) * 0.4 # Good model
>>> y_pred2 = np.random.rand(500) # Random model
>>>
>>> # Generate the plot
>>> ax = plot_polar_confusion_matrix(
...     y_true,
...     y_pred1,
...     y_pred2,
...     names=["Good Model", "Random Model"],
...     normalize=True
... )