4

I have given a set of X, Y coordinate and I need to find the AUC using trapezoidal formula, without using any numpy or sklearn library.

(x0,y0) is always (0,0)
(xn,yn) is always (1,1)

Below diagram

enter image description here

Without using any sklearn library, I understand I need to find below

hi = ?
wi= ?
AUC = sum (hi * wi)

Now I am not sure how to find hi, wi. I don't think I have all the necessary data to do the high school math. Am I missing something?

nad
  • 2,640
  • 11
  • 55
  • 96
  • 2
    It looks like you are trying to calculate the area between two curves, namely between the piecewise linear function along the top and the dash red line, via some modified version of the trapezoidal rule. What you want to do is to calculate the are of the piecewise curve relative to the horizontal axis, so all the blue lines would be truly vertical lines. If you really do need the area between them, you can subtract away the simple area under the dashed line triangle at the very end. – ely Dec 03 '18 at 23:16

1 Answers1

3

The area below (x1, y1) and (x2, y2) (as below vertically, not "diagonaly" like you seem to try to calculate) is simply:

(x2 - x1) * (y1 + y2) / 2 

You can then generalize to other consecutive indices and add all the terms with a for loop.

Normally AUC contains the area of the bottom right half (below your red dashed line) but if you need to take that off, just subtract 1/2 to your final result.

And you might also need to consider the edge case... not sure how you are supposed to consider before the sections between 0 and x0 and between xn and 1...

Julien
  • 13,986
  • 5
  • 29
  • 53