Sobes.tech
Middle — Senior

How is ROC-AUC calculated? Describe the algorithm step-by-step.

sobes.tech AI

Answer from AI

ROC-AUC (Receiver Operating Characteristic - Area Under Curve) is a metric of binary classification quality that reflects the model's ability to distinguish between classes.

Calculation algorithm for ROC-AUC:

  1. Sorting: Sort all objects by predicted probabilities of belonging to the positive class in descending order.
  2. Constructing the ROC curve:
    • Traverse the sorted list, at each step calculate:
      • True Positive Rate (TPR) = TP / (TP + FN)
      • False Positive Rate (FPR) = FP / (FP + TN)
    • TP, FP, FN, TN are updated as the threshold (each probability value) changes.
  3. Area under the curve:
    • Calculate the area under the ROC curve, for example, using the trapezoidal method, integrating TPR over FPR.

The final ROC-AUC value is a number from 0 to 1, where 1 indicates perfect classification, and 0.5 indicates random guessing.

Example:

  • There are 5 objects with probabilities and labels:
    • (0.9, 1), (0.8, 0), (0.7, 1), (0.4, 0), (0.3, 1)
  • Sorted by probability: 0.9(1), 0.8(0), 0.7(1), 0.4(0), 0.3(1)
  • For each threshold, calculate TPR and FPR, plot ROC points, and compute the area.