Skip to content
AI360XpertBeta
Playgrounds

Evaluation & RL

Threshold, Confusion Matrix & ROC

On fixed scored observations, one threshold assigns predictions that determine every confusion count and metric denominator.

Data seed 42

Guided steps 1 / 3

Stage 1 of 3: Two distributions

Same scores, one decision cut

Seed 42, synthetic score separation 1.6. 400 scores: 200 actual positives in the upper lane, 200 actual negatives in the lower lane. Scores are not calibrated probabilities. The decision cut is not revealed yet.

Upper lane: actually positive. Lower lane: actually negative. Both use the same score and count scales; counts are not stacked. Hatched segments are mistakes after the cut is revealed. A bin is split at the exact cut; threshold edits keep the count scale fixed.

  • Actually positive
  • Actually negative
Adjust parameters

How far apart the two score distributions sit.

Row 0: raw score 0.3465489960441609, actual positive.

400 observations: 200 actually positive, 200 actually negative. No model is fitted here.

Can one cut separate overlapping scores?

These synthetic scores have known labels. Separation changes the scoring mechanism; moving the decision threshold later keeps the scores fixed. A score between zero and one is not evidence of calibration.

  1. Fixed scores
  2. Compare with cut
  3. Count four outcomes
  4. Divide by the right population
Score

A number used to rank observations. Its scale alone does not establish calibrated probability.

Check this stage

Check your understanding

Move a cut on fixed observations and trace predictions into confusion counts, precision and recall.

One cut changes the predictions

A decision threshold turns scores into labels. This lab predicts positive when score is at or above the threshold, and negative otherwise. Moving the cut keeps the same observations, scores and actual labels; only predictions change.

The class score distributions overlap, but the histograms occupy separate labelled lanes: actual positives above, actual negatives below. Both use the same score and count scales. Heights count observations; counts are not stacked. Synthetic score separation changes the scoring mechanism, while New data changes the draw. The same seed and separation reproduce the same scores.

These are sigmoid-transformed Gaussian scores, not demonstrated calibrated probabilities. A score of 0.8 does not establish that 80% of similar observations are positive. The calibration guide describes the frequency evidence needed.

Follow one observation into the matrix

In A decision, select an observation, compare its raw score with the cut, make a prediction, then reveal it. Its actual label determines which cell receives that prediction:

Actual labelPredicted negativePredicted positive
NegativeTrue negative (TN)False positive (FP)
PositiveFalse negative (FN)True positive (TP)

Equality predicts positive. Tied scores cross together. Hatched segments count mistakes with this same rule even when the cut lies inside a bin. Under the hood retains every raw observation, prediction and matrix assignment.

What do precision and recall divide by?

Precision asks how many flagged observations are actually positive. Recall asks how many actual positives were found.

P=TPTP+FP,R=TPTP+FNP=\frac{TP}{TP+FP},\qquad R=\frac{TP}{TP+FN}

Take scores and actual labels (0.9, negative), (0.8, positive), (0.5, positive), (0.5, negative), (0.2, negative), (0.1, positive). At threshold 0.5, both equal-score observations are positive: TP=2, FP=2, TN=1, FN=1. Precision is 2/4=0.5, recall is 2/3, accuracy is 3/6=0.5 and F1 is 4/7.

Raise the cut to 0.8: TP=1, FP=1, TN=2, FN=2. At 0.9 the only flagged observation is negative, so precision falls to zero. Precision need not rise when the threshold rises. On fixed rows, recall cannot increase as the cut rises because no new positives enter the shrinking predicted-positive set. Counts change in steps when a score is crossed.

In the generated lab, seed 42 and separation 1.6 at threshold 0.30 give TP=174, FP=102, TN=98 and FN=26. Precision is 174/276, about 0.6304; recall is 174/200=0.87. Compare this with the initial cut on the same rows. These are sample measurements, not population guarantees.

Can predicting nobody look perfect?

Try Predict nobody positive in the final stage. This generated fixture has no score equal to one, so threshold 1 predicts every observation negative. Precision is 0/0: undefined, not 100%. Recall is zero because every actual positive is missed. Libraries may substitute values under a reporting policy.

At threshold zero, every observation is positive. Recall is one here, but all 200 negatives are false positives and precision equals the positive fraction, one half. Inspect the counts before treating one metric as success. Restore experiment restores preceding controls, seed, stage, mode, inspected row and prediction even after further edits.

F1 uses 2TP / (2TP + FP + FN). It can be zero when precision is undefined but actual positives exist; if its own denominator is zero it is undefined. Accuracy, specificity and false positive rate use their own denominators. Undefined is neither numerical divergence nor perfection.

Why does the ROC marker move but AUC stay fixed?

The retained ROC view plots recall against false positive rate, FP / (FP + TN), over distinct score cuts. The marker uses the current matrix. Moving one threshold moves that marker but changes neither the curve nor its area on fixed scores. AUC gives half credit to positive-negative score ties and is undefined without both classes. A sample curve does not prove calibration or future performance.

This lab focuses on a single decision and its counts. The precision-recall curve lab follows with the full precision-recall sweep and prevalence effects.

Choose a policy with evidence

Load the challenge and change only the cut to reach precision at least 0.60 and recall at least 0.80 on the original rows. Neither metric alone determines a deployment policy: false alarms and misses have application-specific consequences. The threshold tuning guide separates scores from decisions and explains why tuning needs separate validation evidence. Repeated exploration of these observations is not an untouched final test.

Sharing reproduces guided display stage, seed, threshold, separation and selected observation. Guesses, recovery, free-exploration identity and local progress stay here. Reset retains stage and seed and restores initial controls in guided mode.

Stage recap

  1. Two distributions

    These synthetic scores have known labels. Separation changes the scoring mechanism; moving the decision threshold later keeps the scores fixed. A score between zero and one is not evidence of calibration.

  2. A decision

    Score at or above the threshold predicts positive, including exact equality. Compare that prediction with the actual label to find TP, FP, TN or FN.

  3. One choice, three readings

    Read the counts behind precision and recall. Raising the cut cannot increase recall on these fixed rows, but precision need not rise. The ROC marker moves; the curve and AUC stay fixed.

Reference

Precision
TP / (TP + FP): of what you flagged, how much was right; undefined without positive predictions
Recall
TP / (TP + FN): of what was there, how much you found; undefined without actual positives
Accuracy
(TP + TN) / total: can hide missed rare positives; undefined on an empty sample
F1
2TP / (2TP + FP + FN): undefined if its own denominator is zero
TPR
same as recall: the ROC y axis
FPR
FP / (FP + TN): the ROC x axis
ROC
every threshold at once, plotted as (FPR, TPR)
AUC
random positive outscores random negative, with half credit for ties; undefined without both classes

Break it on purpose

Predicting no positives misses every actual positive and leaves precision undefined. Predicting everything positive catches all positives but flags every negative too.