# How does a ROC curve work?

{% hint style="info" %}
Source:

* [_Understanding AUC-ROC curve (Sarang Narkhede)_](https://towardsdatascience.com/understanding-auc-roc-curve-68b2303cc9c5)
* [_How and When to Use ROC Curves and Precision-Recall Curves for Classification in Python (Jaon Browniee)_](https://machinelearningmastery.com/roc-curves-and-precision-recall-curves-for-classification-in-python/)
* [_Beyond Accuracy: Precision and Recall (Will Koehrsen)_](https://towardsdatascience.com/beyond-accuracy-precision-and-recall-3da06bea9f6c)
{% endhint %}

## Overview

* **ROC** (Receiver Operating Characteristics) is a **probability curve**.
* **AUC** (Area Under the Curve) represents the degree or measure of separability.
* **AUC-ROC** is a **performance measurement** for classification problems **at various thresholds settings**.
* Range: \[0, 1]
  * Best: 1
  * Worst: 0.5
  * Inverse: 0

![Image courtesy: My Photoshopped Collection](https://569842953-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LmjpNbCRLUyGiAxD8kn%2F-LofB_oZrqsFaAY8u_9e%2F-LofCH_bb_foO2sqXutA%2Fimage.png?alt=media\&token=abec4d93-1db5-4ce3-bff4-e3eb9624455a)

{% hint style="success" %}
A ROC curve plots the **TPR on the y-axis versus the FPR on the x-axis**. The TPR is the **recall** and the FPR is the **probability of a false alarm**.
{% endhint %}

## Understanding the probability curves

When two **distributions overlap**, we introduce **type 1 and type 2 errors**. Depending upon the **threshold**, we can **minimize or maximize them**. A threshold equal to 0.5 will imply the metric we give an equal weight to the sensitivity and specificity of the model.

When we **decrease the threshold**, we get more positive values thus it **increases the** [**recall**](../../ml-techniques/metrics#recall) **and decreasing the** [**specificity**](../../ml-techniques/metrics#specificity). Similarly, when we increase the threshold, we get more negative values thus we get higher specificity and lower recall.

{% tabs %}
{% tab title="AUC_ROC = 1" %}
In the **ideal situation**, the distribution curve of the **positive class is equal** to the distribution of the **negative** one.

![](https://569842953-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LmjpNbCRLUyGiAxD8kn%2F-LofB_oZrqsFaAY8u_9e%2F-LofHsXoI90msz_PLZLj%2Fimage.png?alt=media\&token=39b39db5-8048-45d7-83f7-43b72c41203f)
{% endtab %}

{% tab title="AUC_ROC = 0.7" %}
![](https://569842953-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LmjpNbCRLUyGiAxD8kn%2F-LofB_oZrqsFaAY8u_9e%2F-LofHnYBPe2AsuMssk_x%2Fimage.png?alt=media\&token=e0c64dd9-ae9e-4cab-981b-c671228e0c0a)
{% endtab %}

{% tab title="AUC_ROC = 0.5" %}
When AUC is approximately 0.5, the model has **no discrimination capacity** to distinguish between positive class and negative class.

![](https://569842953-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LmjpNbCRLUyGiAxD8kn%2F-LofB_oZrqsFaAY8u_9e%2F-LofI34EyCNR9Z17oF8z%2Fimage.png?alt=media\&token=3063fec7-c12a-4c5b-8954-bb8e09210df9)
{% endtab %}

{% tab title="AUC_ROC = 0" %}
When AUC is approximately 0, the model is **actually reciprocating the classes**. It means the model is predicting a negative class as a positive class and vice versa.

![](https://569842953-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LmjpNbCRLUyGiAxD8kn%2F-LofB_oZrqsFaAY8u_9e%2F-LofIVFNEpr0aWJ-8i-W%2Fimage.png?alt=media\&token=eb7df439-8f17-48e4-ae88-69094b0cde14)
{% endtab %}
{% endtabs %}

{% hint style="success" %}
&#x20;Finally, we can quantify a model’s ROC curve by calculating the total [Area Under the Curve (AUC)](https://en.wikipedia.org/wiki/Receiver_operating_characteristic#Area_under_the_curve).
{% endhint %}

To make this clear:

* Smaller values on the x-axis of the plot indicate lower false positives and higher true negatives.
* Larger values on the y-axis of the plot indicate higher true positives and lower false negatives.

### Dealing with multiclass models

Using the _One-vs-All_ methodology,  we can plot _N_ AUC-ROC curves for the given _N_ classes.
