Based TPR and FPR, I have generate ROC curve for my binary classification model. I do not know, how to calculate AUC value. I would be very help for me if you can help me to calculate AUC value.

  • 1
    $\begingroup$ This might help blog.revolutionanalytics.com/2016/11/calculating-auc.html $\endgroup$
    – Aditya
    Nov 2, 2018 at 1:53
  • $\begingroup$ Thanks for your answer. Anyone can help me by explaining with simple example? $\endgroup$
    – Reja
    Nov 2, 2018 at 10:19
  • $\begingroup$ Where exactly are you being troubled? $\endgroup$
    – Aditya
    Nov 2, 2018 at 12:20

1 Answer 1


Welcome to the community!

As you know, AUC is just the area under ROC curve. So the question is more about numerical methods as you have a set of points and you would like to calculate the area under it.

Riemannian Sum

Trivial solution. Simply make rectangles from points you have. The area of each rectangle is simply the product of edges. Then sum them up! You probably don't like it do you?!

Trapezoidal Method

After Riemannian, the simplest and most naive algorithm to do this. You simply have a set of points and you just calculate the trapezoidal area between each pair and sum them up like what you see in the figure below. It has the maximum computation error as it simplifies the problem a lot.

enter image description here

Simpson (1/3) Method

Much better when we are talking about curves! Let's keep it simple and to the point. You can model your function in every interval using a quadratic ($y=ax^2+bx+c$) and having 3 data points. Using your three data points, you can calculate $a$, $b$ and $c$. Then the area under curve is not that difficult, but we have a better solution! Trust me or not, the value of this integration is simply

$$\frac{b-a}{6} (f(a)+4\times f(m)+f(b))$$

where $(a,f(a))$ and $(b,f(b))$ are endpoints of interval and $(m,f(m))$ is the midpoint. See the image below from here to compare these methods.

enter image description here

Romberg Methods

Simpson and/or Trapezoidal methods can be recursively applied to achieve a more accurate calculation. It's called Romberg method. Accuracy of these methods were in the length of interval. Smaller intervals give more accurate integration. Romberg uses this fact to iteratively get closer to more accurate answer.

And of course tones of more algorithms to do that.

PS: You certainly have libraries and functions in different languages to calculate it for you. Scipy offers for Python for instance.

Hope it helps! Good Luck!

  • $\begingroup$ I am glad it helped :) $\endgroup$ Nov 4, 2018 at 12:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.