All problems
AUC by Trapezoid
Problem
Compute the area under a curve given its points using the trapezoidal rule: sum over consecutive segments of (x1 - x0) * (y0 + y1) / 2.
Return 0.0 if there are fewer than two points.
Hint
Add the area of a trapezoid for every pair of neighboring points.
Test cases
case 1
in: [[[0,0],[0,1],[1,1]]]
expected: 1
case 2
in: [[[0,0],[1,1]]]
expected: 0.5
case 3
in: [[[0,0],[0.5,0.5],[1,1]]]
expected: 0.5
case 4
in: [[]]
expected: 0
Starter codePython
def auc_trapezoid(roc_points):
# Your code here
pass4 test cases · run your code against them in the editor