I know that if I have some function f(x) that describes a curve, I can approximate the area under the curve using the trapezoid rule as follows:
def auc(f, a, b, n): subinterval = (b - a) / n s = f(a) + f(b) i = 1 while i < n: s += 2 * f(a + i * subinterval) i += 1 return (subinterval / 2) * s
However, I am trying to implement the trapezoid rule to approximate the area under the ROC curve. I don't have the function f(x), but rather true positive rates and false positive rates at thresholds from 0 to 1 spaced by .01. I tried to implement the rule following this guide https://byjus.com/maths/trapezoidal-rule/ as so:
def roc_auc(tprs, fprs): y_sum = max(tprs) + min(tprs) for i in range(1, len(fprs)-1): y_sum += 2*tprs[i] interval = (max(fprs) - min(fprs)) / len(fprs) return ((interval / 2) * y_sum) / 100
However, when I test it against auc functions implemented in numpy, scikit, etc. I get different values than the one I calculate so I know I'm doing something wrong. Can anyone tell me where I'm going wrong?