Threshold Sweep
One score can produce different decisions. Compare F1 at candidate thresholds on validation labels; break equal scores toward the smaller threshold.
scores = [0.2, 0.6, 0.9]
print([int(score >= 0.5) for score in scores])From arithmetic to an experiment
One score can produce different decisions. Compare F1 at candidate thresholds on validation labels; break equal scores toward the smaller threshold. The trace reads the local variables of your function as it executes. Change one input or parameter, predict the result, then run the checks again. A small deterministic example makes arithmetic mistakes easier to locate than a long training run. State the shape and meaning of the returned value before coding. Keep preprocessing, evaluation and model updates in their proper order, and examine the boundary case in each check. The companion lab lets you replay intermediate values while the same algorithm runs.
Your task
choose_threshold(scores, labels, candidates) returns the candidate with greatest binary F1, choosing the smallest on a tie. A score >= threshold predicts 1; candidates is nonempty.
The explanation opens here once every check passes.