ROC AUC (Trapezoidal)

HardMachine LearningMathSorting

Description

Given the points of an ROC curve as [false positive rate, true positive rate] pairs sorted by increasing false positive rate, return the area under the curve computed with the trapezoidal rule. Round the result to 4 decimal places.

Examples

Input:[[0,0],[1,1]]
Output:0.5
Explanation:

Consecutive points form trapezoids whose areas are added up to approximate the region beneath the ROC curve.

Input:[[0,0],[0,1],[1,1]]
Output:1
Explanation:

Consecutive points form trapezoids whose areas are added up to approximate the region beneath the ROC curve.

Input:[[0,0],[0.5,0.8],[1,1]]
Output:0.65
Explanation:

Consecutive points form trapezoids whose areas are added up to approximate the region beneath the ROC curve.

Constraints

  • 2 ≤ number of points ≤ 10⁴
  • points sorted by false positive rate

Ready to solve this problem?

Practice solo and sharpen your skills for technical interviews.