Track improvements with patience
Validation loss can stop improving before training loss does. Early stopping watches a held-out metric and tolerates a bounded number of consecutive non-improvements. A minimum improvement avoids resetting patience for tiny numerical changes. The comparison must be against the best accepted value, and the first observation initializes that value rather than consuming patience.
best, loss, min_delta = 0.5, 0.49, 0.02
print(loss < best - min_delta)Think before coding
Patience measures consecutive failures to improve the accepted best. A genuine improvement resets that run. The function returns the stopping decision; checkpointing the best model is a separate responsibility. Work through the example by hand before changing the starter. Decide what should happen for an empty input, a single value and a repeated value where those cases apply. The checks use several inputs so a hard-coded answer cannot stand in for the rule.
Your task
Write stop_epoch(losses, patience, min_delta=0.0). patience is positive. Return the zero-based epoch where consecutive non-improvements first reach patience, or None. Improvement means loss < best - min_delta; the first loss initializes best.
The explanation opens here once every check passes.