# How can I calculate AUC from the ROC curve for the classification?

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.

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.

## 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.

## 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!

• I am glad it helped :) – Kasra Manshaei Nov 4 '18 at 12:27