Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Keras · Class

metrics.AUC

keras.metrics.AUC estimates the area under a ROC or precision-recall curve for binary or multi-label classification. It accumulates thresholded confusion statistics and returns the approximated area as a scalar metric.

How it works

AUC accumulates classification statistics across predefined prediction thresholds and estimates the area under either a ROC or precision-recall curve. Call update_state() with labels and predictions, then result() to obtain the current scalar; the approximation uses bucketed values and a selected summation method.

Syntax

keras.metrics.AUC(num_thresholds=200, curve="ROC", summation_method="interpolation", name=None, dtype=None, thresholds=None, multi_label=False, num_labels=None, label_weights=None, from_logits=False)

Parameters

NameTypeDescription
num_thresholdsintNumber of thresholds used to discretize the ROC curve; must be greater than 1 and defaults to 200.
curvestrCurve to compute: "ROC" or "PR"; defaults to "ROC".
summation_methodstrMethod used to sum the discretized curve.
namestr or NoneOptional metric name.
dtypestr or NoneOptional metric dtype.
thresholdslist or NoneExplicit threshold values instead of the default linearly spaced thresholds.
multi_labelboolWhether inputs represent multiple labels.
num_labelsint or NoneNumber of labels for multi-label data.
label_weightslist or NoneOptional weights for labels.
from_logitsboolWhether predictions are logits rather than probabilities.

Returns

A scalar tensor containing the estimated AUC, returned by result().

Key points

  • AUC estimates the area under either the ROC curve or the precision-recall curve.
  • Predictions are grouped into value buckets, and per-bucket averages are interpolated to estimate the curve area.
  • Unlike accuracy, the metric summarizes model behavior across all operating points.
  • num_thresholds controls how finely the curve is discretized; its default is 200.
  • Use curve="ROC" for ROC-AUC or curve="PR" for PR-AUC.
  • The implementation tracks true positives, true negatives, false positives, and false negatives to construct the estimate.

Common mistakes

  • num_thresholds must be greater than one; otherwise the metric cannot discretize the curve correctly.

Example: Compute ROC-AUC from predictions

import keras

x = [0.1, 0.9, 0.8, 0.2]
y = [0, 1, 1, 0]

auc = keras.metrics.AUC(curve="ROC")
auc.update_state(y, x)
print(float(auc.result()))

Creates a ROC-AUC metric, accumulates labels and predicted probabilities, then reads the scalar result.

When to use it

Monitor ROC-AUC during training

Binary classification with probability outputs.

Track PR-AUC

Imbalanced binary classification where precision and recall matter.

Evaluate logits directly

Models producing raw scores before sigmoid or softmax conversion.

Measure multi-label performance

Multiple independent labels per example.

Interview questions

QWhat does keras.metrics.AUC measure?

AUC estimates the area under a ROC or precision-recall curve. It accumulates predictions into threshold buckets and computes the area from the resulting precision, recall, or false-positive-rate values.

Follow-up: Why can the value differ from an exact ranking-based AUC? Because Keras uses a finite threshold grid and a Riemann-sum approximation, so increasing num_thresholds can improve resolution.

QHow do ROC and PR modes differ?

curve selects the curve type: ROC is the default, while PR requests the precision-recall curve. ROC-AUC and PR-AUC evaluate model behavior across operational points rather than one classification threshold.

Follow-up: When might PR-AUC be preferable? It is often more informative when positive examples are uncommon because it focuses on precision and recall.

QHow is AUC accumulated during evaluation?

The metric is stateful: update_state() accumulates the batch statistics, and result() returns the current scalar AUC. A reset_state() call is used to clear accumulated state before a new evaluation period.

Follow-up: What happens if state is not reset? Results combine observations from multiple periods, so the reported metric no longer represents only the intended dataset.

  • keras.metrics.Precision
  • keras.metrics.Recall
  • keras.metrics.TruePositives
  • keras.metrics.TrueNegatives
  • keras.metrics.FalsePositives
  • keras.metrics.FalseNegatives
  • keras.metrics.PrecisionAtRecall

Source: Classification metrics based on True/False positives & negatives. Checked 2026-10-15.