ML Foundations

Compare binary ROC AUC from logits and probabilities

Understand when a sigmoid transformation preserves a binary ranking score.

Example results for Compare binary ROC AUC from logits and probabilities. logit AUC: 0.75
Illustration: Original illustration by Tensor Almanac
Evidence and testing

Review record: Tensor Almanac automated evidence gate (no independent human review). Example versions, recorded outputs and limitations appear below.

The score ordering matters

Binary ROC AUC can use positive-class probabilities or non-thresholded decision scores. It summarizes discrimination across thresholds; it does not require that the input itself be a calibrated probability. [1]

Applying the same strictly increasing transform to every score preserves the ranking in exact arithmetic. The sigmoid function is strictly increasing, so converting each binary logit to a probability preserves that ranking. In finite precision, saturation can create ties, so check actual outputs rather than assuming exact equality for extreme scores. [2]

References: [1], [2]

Count positive and negative pairs

Run python examples/binary_roc_score_ranking.py. The fixture has two positives and two negatives. For each positive-negative pair, the example awards one point when the positive is higher, half for a tie, and zero otherwise. Three of the four pairs are correctly ordered, giving 0.75.

After applying sigmoid, the same four pairs retain their order and the score remains 0.75. This is a small binary example computed directly in NumPy. A separate local scikit-learn check returned the same AUC for both arrays. [1]

Executed with local Python and NumPy; stdout and checksum are stored in private evidence.

import numpy as np

truth = np.array([0, 1, 0, 1])
logits = np.array([-2.0, -1.0, 0.0, 2.0])
probabilities = 1 / (1 + np.exp(-logits))

def pair_auc(values):
    positive = values[truth == 1]
    negative = values[truth == 0]
    return float(np.mean((positive[:, None] > negative).astype(float) +
                         0.5 * (positive[:, None] == negative)))

raw_auc = pair_auc(logits)
prob_auc = pair_auc(probabilities)
assert np.isclose(raw_auc, 0.75) and np.isclose(prob_auc, raw_auc)
print("logit AUC:", raw_auc)
print("sigmoid AUC:", prob_auc)
print("same order:", bool(np.array_equal(np.argsort(logits), np.argsort(probabilities))))

Recorded output

logit AUC: 0.75
sigmoid AUC: 0.75
same order: True

References: [1]

Keep score meaning and evaluation scope explicit

Use scores oriented toward the chosen positive class. In binary scikit-learn ROC AUC, probability inputs correspond to the class with the greater label; confirm the model class ordering before selecting a probability column. [1]

Ranking quality and probability calibration answer different questions. A high AUC does not by itself show whether predicted probabilities match observed frequencies. This example does not cover multiclass AUC, missing classes, sample weights, extreme logits or fitted-model calibration. [1, 2]

References: [1], [2]

Sources

  1. scikit-learn ROC AUC
  2. scikit-learn calibration