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, kind='polar', 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_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.

titlestr, default=”Polar Classification Report”

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 of the three metrics (Precision, Recall, F1-Score).

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. The value is validated with validate_kind (case-insensitive); invalid values raise ValueError("kind must be 'polar' or 'cartesian'.").

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:

See also

plot_polar_confusion_multiclass

A plot showing the raw counts of predictions.

sklearn.metrics.classification_report

The underlying scikit-learn function.

Notes

This plot visualizes the three most common metrics for evaluating a multiclass classifier on a per-class basis [1].

  1. Precision: The ability of the classifier not to label as positive a sample that is negative.

    (1)\[\text{Precision} = \frac{TP}{TP + FP}\]
  2. Recall (Sensitivity): The ability of the classifier to find all the positive samples.

    (2)\[\text{Recall} = \frac{TP}{TP + FN}\]
  3. 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"
... )