# Receiver Operating Characteristic (ROC) Curve

The Receiver Operator Characteristic (ROC) curve visually demonstrates the predictive ability of a binary classifier system. While it was originally developed within the realm of signal detection theory, it is now widely applied in diverse fields such as healthcare, radiology, natural disaster forecasting, and machine learning. The extensive usage of ROC reaffirms its immense significance.

## Formulating ROC curve

To construct an ROC curve in the sphere of machine learning, the True Positive Rate (TPR) is plotted against the False Positive Rate (FPR). The TPR, calculated as TP/(TP + FN), represents the correct prediction of all positive observations. Likewise, FPR (FP/(TN + FP)) denotes the portion of negative observations inaccurately projected as positive. Using medical testing as an illustration, TPR is the percentage of patients correctly identified as test-positive for a particular disease.

The ROC curve leverages both TPR and FPR across multiple classification thresholds. Lowering the classification limit categorizes more items as positive, augmenting both False Positives and True Positives simultaneously.

Regarding ROC space, a discrete classifier returning only the anticipated class yields a singular point. However, we can create a curve with probabilistic classifiers, which denote the likelihood to which an instance relates to one class over the other, by revising the score threshold.

Manipulating certain discrete classifiers into scoring classifiers is viable by investigating their instance data. A decision tree, for instance, utilizes the proportion of instances at a leaf node to ascertain the node's class.

## Analyzing the ROC curve

The ROC curve demonstrates the equilibrium between TPR (sensitivity) and 1 – FPR (specificity). Models with curves inching nearer to the top-left corner perform exceptionally. A diagonal (FPR = TPR) point depicts a random classifier and is an apt baseline. As the curve approaches the 45-degree diagonal of the ROC space, the test's precision decreases.

Notably, class distribution doesn't influence ROC, making it perfect for evaluating classifiers predicting rare occurrences like diseases or natural calamities. Contrarily, using accuracy ((TP + TN) / (FN + FP + TP + TN)) would bias towards classifiers forecasting negative outcomes for rare events.

AUC (area under the curve)

When contrasting diverse classifiers, it's beneficial to encapsulate each classifier's performance into a singular metric. This process is typically accomplished by determining the area under the ROC curve or AUC.

A stellar model possesses an AUC nearing 1, indicative of excellent separability. Conversely, a model with an AUC approaching 0 is poor, exhibiting the least separability measure, inaccurately predicting 1s as 0s and vice versa. If the area under the curve equals 0.5, the model fails in differentiating classes.

Given its ability to rank randomly chosen negative instances lower than positive ones, a classifier with a high AUC may still underperform at specific instances compared to those with a lower AUC. However, AUC serves as a good generic indicator of predictive precision.

AUC draws preference due to two reasons:

1. AUC is scale-invariant, assessing prediction order rather than absolute values.
2. AUC remains insensitive to classification thresholds, gauging model prediction accuracy irrespective of the categorization level utilized.

However, these traits come with constraints that may limit AUC's usefulness in certain scenarios:

• Scale-invariance may not always be beneficial. Instances necessitating accurately calibrated probability outputs would not find AUC informative.
• Classification threshold invariance may not always be desired. In cases where one classification error type needs minimization due to a significant cost difference between false negatives and false positives, AUC might not be the best metric. For instance, in email spam detection, prioritizing a decrease in false positives might be crucial, despite a potential surge in false negatives. For such optimization, AUC isn't suitable.
Integrate | Scan | Test | Automate

## Detect hidden vulnerabilities in ML models, from tabular to LLMs, before moving to production.  