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_true
np.ndarray 1D array of true binary labels (0 or 1).
- *y_preds
np.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.
- names
listofstr,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). 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 model’s set of bars.
- 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.
- y_true
- Returns:
- ax
matplotlib.axes.Axes The Matplotlib Axes object containing the plot.
- ax
- Parameters:
See also
plot_polar_confusion_multiclassThe companion plot for multiclass problems.
sklearn.metrics.confusion_matrixThe 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 ... )