Implementation:Rapidsai Cuml Ranking Metrics
| Knowledge Sources | |
|---|---|
| Domains | Machine_Learning, Classification, Ranking, Model_Evaluation |
| Last Updated | 2026-02-08 12:00 GMT |
Overview
Provides GPU-accelerated ranking and threshold-based evaluation metrics including precision-recall curves and ROC AUC scores for binary classification.
Description
The _ranking.py module implements two public functions for evaluating binary classifiers by their predicted scores / probabilities:
precision_recall_curve-- Computes precision and recall values at every unique probability threshold. Returns three arrays: precision, recall, and thresholds. The last precision value is 1.0 and the last recall value is 0.0, ensuring the curve starts on the y-axis.
roc_auc_score-- Computes the Area Under the Receiver Operating Characteristic Curve (ROC AUC). A score of 1.0 indicates a perfect classifier; 0.5 indicates random guessing.
Internally, both rely on a shared _binary_clf_curve helper that sorts predictions, groups tied scores using a custom CuPy RawKernel (_addup_x_in_group), and accumulates true-positive and false-positive counts via cumulative sums. The trapezoidal rule is used to compute the area under the ROC curve.
Usage
Use these functions to evaluate binary classifiers that output probability scores or decision function values. They are used during model selection and hyperparameter tuning to assess ranking quality, calibration, and discrimination ability.
Code Reference
Source Location
- Repository: Rapidsai_Cuml
- File:
python/cuml/cuml/metrics/_ranking.py
Signature
def precision_recall_curve(
y_true, probs_pred
) -> typing.Tuple[CumlArray, CumlArray, CumlArray]
def roc_auc_score(y_true, y_score) -> float
Import
from cuml.metrics import precision_recall_curve
from cuml.metrics import roc_auc_score
I/O Contract
Inputs -- precision_recall_curve
| Name | Type | Required | Description |
|---|---|---|---|
| y_true | array-like of shape (n_samples,) | Yes | True binary labels, values in {0, 1}. |
| probs_pred | array-like of shape (n_samples,) | Yes | Estimated probabilities or decision function output. |
Inputs -- roc_auc_score
| Name | Type | Required | Description |
|---|---|---|---|
| y_true | array-like of shape (n_samples,) | Yes | True binary labels, values in {0, 1}. |
| y_score | array-like of shape (n_samples,) | Yes | Target scores (probability estimates or decision function values for the positive class). |
Outputs -- precision_recall_curve
| Name | Type | Description |
|---|---|---|
| precision | array of shape (n_thresholds + 1,) | Precision values; element i is the precision of predictions with score >= thresholds[i]. The last element is 1.0. |
| recall | array of shape (n_thresholds + 1,) | Decreasing recall values; element i is the recall of predictions with score >= thresholds[i]. The last element is 0.0. |
| thresholds | array of shape (n_thresholds,) | Increasing score thresholds used to compute precision and recall. |
Outputs -- roc_auc_score
| Name | Type | Description |
|---|---|---|
| auc | float | Area Under the ROC Curve. 1.0 is perfect, 0.5 is random. |
Usage Examples
import cupy as cp
from cuml.metrics import precision_recall_curve, roc_auc_score
y_true = cp.array([0, 0, 1, 1])
y_scores = cp.array([0.1, 0.4, 0.35, 0.8])
# Precision-Recall Curve
precision, recall, thresholds = precision_recall_curve(y_true, y_scores)
print("Precision:", precision)
print("Recall:", recall)
print("Thresholds:", thresholds)
# ROC AUC Score
auc = roc_auc_score(y_true, y_scores)
print("ROC AUC:", auc) # 0.75