Early Stopping Tracker

easy
Unit 2 · Training0/3 to milestone

Training too long overfits. Early stopping watches the validation loss and stops once it hasn't improved for a while.

Implement a class EarlyStopping(patience=3, min_delta=0.0) with:

  • step(val_loss) -> bool: record one epoch's validation loss and return True if training should stop now.
    • An epoch counts as an improvement if val_loss < best - min_delta. Then update best, remember this epoch as best_epoch (epochs count from 0) and reset the counter.
    • Otherwise increment the counter. Stop once it reaches patience.
  • attributes best (start at infinity) and best_epoch (start at None).

Example (patience 2): losses 1.0, 0.8, 0.85, 0.9 → stop on the 4th call; best = 0.8, best_epoch = 1.

#training#overfitting2 visible + 3 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Early Stopping Tracker · TechGradify