Compute AUC (Area Under ROC)
Compute AUC (Area Under ROC)
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)dFPRApproximated using the trapezoidal rule:
AUC≈i=1∑n−121(TPRi+TPRi+1)(FPRi+1−FPRi)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)
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
Log in to take notes on this problem
Accepts: array
Accepts: array
Compute AUC (Area Under ROC)
Compute AUC (Area Under ROC)
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)dFPRApproximated using the trapezoidal rule:
AUC≈i=1∑n−121(TPRi+TPRi+1)(FPRi+1−FPRi)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)
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
Log in to take notes on this problem
Accepts: array
Accepts: array