Problems
Loading...
1 / 1

Compute AUC (Area Under ROC)

Metrics & Evaluation
Easy

Given FPR and TPR arrays from a ROC curve, compute the AUC (Area Under Curve) using the trapezoidal rule.

The AUC provides a single scalar metric that summarizes the performance of a binary classifier across all classification thresholds. It represents the probability that the classifier will rank a randomly chosen positive instance higher than a randomly chosen negative instance.

AUC Formula:

AUC=01TPR(FPR)dFPR\mathrm{AUC} = \int_{0}^{1} \mathrm{TPR}(\mathrm{FPR}) \, d\mathrm{FPR}

Approximated using the trapezoidal rule:

AUCi=1n112(TPRi+TPRi+1)(FPRi+1FPRi)\mathrm{AUC} \approx \sum_{i=1}^{n-1} \frac{1}{2} \left( \mathrm{TPR}_{i} + \mathrm{TPR}_{i+1} \right) \left( \mathrm{FPR}_{i+1} - \mathrm{FPR}_{i} \right)

Function Arguments

  • fpr: array-like, shape (M,) - False Positive Rate values (increasing)
  • tpr: array-like, shape (M,) - True Positive Rate values (same length as fpr)
Loading visualization...

Examples

Input: fpr=[0,0,1], tpr=[0,1,1]

Output: 1.0

Input: fpr=[0,1], tpr=[0,1]

Output: 0.5

Hint 1

Use np.trapezoid() for trapezoidal integration.

Hint 2

Validate that fpr and tpr have the same length and at least 2 points.

Hint 3

The result should be a scalar float, not an array.

Requirements

  • Return single float value in range [0, 1]
  • Use trapezoidal integration (no external libraries)
  • Handle edge cases: perfect (AUC=1.0), random (AUC=0.5), worst (AUC=0.0)

Constraints

  • M ≥ 2; NumPy only
  • Time limit: 50ms; Memory: 64MB
Try Similar Problems