kdiagram.plot.evaluation.plot_polar_roc¶
- kdiagram.plot.evaluation.plot_polar_roc(y_true, *y_preds, names=None, title='Polar ROC Curve', figsize=(8, 8), cmap='viridis', show_grid=True, grid_props=None, savefig=None, dpi=300)[source]¶
Plots a Polar Receiver Operating Characteristic (ROC) Curve.
This function visualizes the performance of binary classification models by mapping the standard ROC curve onto a polar plot. It is a novel visualization developed as part of the analytics framework in [1].
- 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.
- names
listofstr,optional Display names for each of the models. If not provided, generic names like
'Model 1'will be generated.- title
str, default=”PolarROCCurve” 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 curve.
- 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.
- 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_pr_curveA companion plot for precision-recall.
sklearn.metrics.roc_curveThe underlying scikit-learn function.
Notes
A Receiver Operating Characteristic (ROC) curve is a standard tool for evaluating binary classifiers [2]. It plots the True Positive Rate (TPR) against the False Positive Rate (FPR) at various threshold settings.
(1)¶\[\text{TPR} = \frac{TP}{TP + FN} \quad , \quad \text{FPR} = \frac{FP}{FP + TN}\]This function adapts the concept to a polar plot:
The angle (θ) is mapped to the False Positive Rate, spanning from 0 at 0° to 1 at 90°.
The radius (r) is mapped to the True Positive Rate, spanning from 0 at the center to 1 at the edge.
A model with no skill (random guessing) is represented by a perfect Archimedean spiral. A good model will have a curve that bows outwards, maximizing the area under the curve (AUC).
References
Examples
>>> import numpy as np >>> from sklearn.datasets import make_classification >>> from kdiagram.plot.evaluation import plot_polar_roc >>> >>> # Generate synthetic binary classification data >>> X, y_true = make_classification( ... n_samples=500, n_classes=2, random_state=42 ... ) >>> >>> # Simulate predictions from two models >>> y_pred_good = y_true * 0.7 + np.random.rand(500) * 0.3 >>> y_pred_bad = np.random.rand(500) >>> >>> # Generate the plot >>> ax = plot_polar_roc( ... y_true, ... y_pred_good, ... y_pred_bad, ... names=["Good Model", "Random Model"] ... )