TensorTonicTensorTonic
Problems
Study PlansProjectsNewInterviewPricingFeedback
Problems
Loading...
1 / 1

Compute AUC (Area Under ROC)

Metrics & Evaluation
Easy

Compute the area under a ROC curve with the trapezoidal rule. For consecutive points (xi,yi)=(FPR⁡i,TPR⁡i)(x_i,y_i)=(\operatorname{FPR}_i,\operatorname{TPR}_i)(xi​,yi​)=(FPRi​,TPRi​):

AUC⁡=∑i=1M−1(xi+1−xi)yi+yi+12\operatorname{AUC} = \sum_{i=1}^{M-1}(x_{i+1}-x_i)\frac{y_i+y_{i+1}}{2}AUC=i=1∑M−1​(xi+1​−xi​)2yi​+yi+1​​

Here, MMM is the number of curve points. Return the summed area as a Python float.

Loading visualization...

Examples

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

Output: 1.0

Explanation: The curve rises vertically to a true-positive rate of one before spanning the full false-positive range.

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

Output: 0.5

Hint 1

Use np.diff(fpr) for trapezoid widths.

Hint 2

Use 0.5 * (tpr[:-1] + tpr[1:]) for their heights.

Requirements

  • Compute each interval width from consecutive FPR values
  • Multiply by the average of the neighboring TPR values
  • Sum all trapezoid areas
  • Return a Python float

Constraints

  • fpr and tpr have the same length of at least two
  • fpr is nondecreasing
  • Both arrays contain values between 0 and 1
  • Use NumPy only
Try Similar Problems
Metrics F1 MicroIou Bounding BoxNdcgRoc CurveClassification Metrics

Sign in to take notes on this problem

Case 1
Case 2

Accepts: array

Accepts: array

You must run your code first.
PrevNext

Compute AUC (Area Under ROC)

Metrics & Evaluation
Easy

Compute the area under a ROC curve with the trapezoidal rule. For consecutive points (xi,yi)=(FPR⁡i,TPR⁡i)(x_i,y_i)=(\operatorname{FPR}_i,\operatorname{TPR}_i)(xi​,yi​)=(FPRi​,TPRi​):

AUC⁡=∑i=1M−1(xi+1−xi)yi+yi+12\operatorname{AUC} = \sum_{i=1}^{M-1}(x_{i+1}-x_i)\frac{y_i+y_{i+1}}{2}AUC=i=1∑M−1​(xi+1​−xi​)2yi​+yi+1​​

Here, MMM is the number of curve points. Return the summed area as a Python float.

Loading visualization...

Examples

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

Output: 1.0

Explanation: The curve rises vertically to a true-positive rate of one before spanning the full false-positive range.

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

Output: 0.5

Hint 1

Use np.diff(fpr) for trapezoid widths.

Hint 2

Use 0.5 * (tpr[:-1] + tpr[1:]) for their heights.

Requirements

  • Compute each interval width from consecutive FPR values
  • Multiply by the average of the neighboring TPR values
  • Sum all trapezoid areas
  • Return a Python float

Constraints

  • fpr and tpr have the same length of at least two
  • fpr is nondecreasing
  • Both arrays contain values between 0 and 1
  • Use NumPy only
Try Similar Problems
Metrics F1 MicroIou Bounding BoxNdcgRoc CurveClassification Metrics

Sign in to take notes on this problem

Case 1
Case 2

Accepts: array

Accepts: array

You must run your code first.