PythiloLesson 8 of 8 · progress kept in this browser

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)
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.

All lessons