#166Overfitting — read the learning curvesEasy

Overfitting — read the learning curves

Background

The signature of overfitting is a diverging pair of curves: the training loss keeps falling while the validation loss turns back up. The model is still improving on examples it has seen, but getting worse on held-out data — it's memorising noise.

Problem statement

Implement is_overfitting(train_losses, val_losses) that returns whether the most recent epoch shows the overfitting signature: training loss decreased but validation loss increased from the previous epoch.

Input

  • train_losses — list of per-epoch training losses (length 2\ge 2).
  • val_losses — list of per-epoch validation losses, same length.

Output

Returns a bool: True if train_losses[-1] < train_losses[-2] and val_losses[-1] > val_losses[-2], else False.

Examples

Example 1 — classic overfitting

Input:  train_losses = [0.5, 0.3], val_losses = [0.4, 0.5]
Output: True

Explanation: training improved (0.50.30.5\to0.3) while validation worsened (0.40.50.4\to0.5).

Example 2 — both still improving

Input:  train_losses = [0.5, 0.3], val_losses = [0.5, 0.4]
Output: False

Explanation: validation is still dropping, so no overfitting signal yet.

Constraints

  • Compare only the last two epochs.
  • Both conditions must hold (train down and val up).
  • Return a Python bool.

Notes

  • This local check is the trigger behind early stopping: when it fires persistently (over a patience window), training has started baking in noise.
Python
Loading...

▶ Run executes the 3 visible sample tests below in your browser. Submit runs the full suite — including hidden tests — on the server for an official verdict.

  • Example: classic overfitting signature
  • Reference: both curves still improving
  • Sample: flat validation is not increasing