kdiagram.plot.evaluation.plot_polar_classification_report¶
- kdiagram.plot.evaluation.plot_polar_classification_report(y_true, y_pred, class_labels=None, title='Polar Classification Report', figsize=(8, 8), cmap='tab10', colors=None, show_grid=True, grid_props=None, mask_radius=False, acov='full', zero_at='N', clockwise=True, savefig=None, dpi=300, ax=None)[source]¶
Plots a Polar Classification Report.
This function creates a grouped polar bar chart to visualize the key performance metrics (Precision, Recall, and F1-Score) for each class in a multiclass classification problem. It provides a detailed, per-class summary of a classifier’s performance.
- 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.- title
str, default=”PolarClassificationReport” 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 of the three metrics (Precision, Recall, F1-Score).
- 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_multiclassA plot showing the raw counts of predictions.
sklearn.metrics.classification_reportThe underlying scikit-learn function.
Notes
This plot visualizes the three most common metrics for evaluating a multiclass classifier on a per-class basis [1].
Precision: The ability of the classifier not to label as positive a sample that is negative.
(1)¶\[\text{Precision} = \frac{TP}{TP + FP}\]Recall (Sensitivity): The ability of the classifier to find all the positive samples.
(2)¶\[\text{Recall} = \frac{TP}{TP + FN}\]F1-Score: The harmonic mean of precision and recall, providing a single score that balances both.
(3)¶\[\begin{split}\text{F1-Score} = 2 \cdot \frac{\text{Precision} \cdot \text{Recall}}\\ {\text{Precision} + \text{Recall}}\end{split}\]
Each class is assigned an angular sector, and within that sector, three bars are drawn, with their heights (radii) corresponding to the scores for these metrics.
References
Examples
>>> import numpy as np >>> from sklearn.datasets import make_classification >>> from kdiagram.plot.evaluation import plot_polar_classification_report >>> >>> # Generate synthetic multiclass data >>> X, y_true = make_classification( ... n_samples=1000, ... n_classes=4, ... n_informative=10, ... flip_y=0.2, ... random_state=42 ... ) >>> # Simulate predictions >>> y_pred = y_true.copy() >>> # Add some errors >>> y_pred[np.random.choice(1000, 150, replace=False)] = 0 >>> >>> # Generate the plot >>> ax = plot_polar_classification_report( ... y_true, ... y_pred, ... class_labels=["Class A", "Class B", "Class C", "Class D"], ... title="Per-Class Performance Report" ... )