← Lesson
Overfitting
Joeven
Run
Reset
Python loads on first run
train_x = [0, 1, 2, 3, 4] train_y = [0.2, 2.1, 3.7, 6.4, 7.8] # roughly 2x val_x = [0.5, 1.5, 2.5, 3.5] val_y = [1.0, 3.0, 5.0, 7.0] def predict_linear(x): return 2.0 * x mem = dict(zip(train_x, train_y)) def predict_mem(x): return mem.get(x, 0.0) def mse(xs, ys, fn): return sum((fn(x) - y) ** 2 for x, y in zip(xs, ys)) / len(xs) print("linear train MSE", round(mse(train_x, train_y, predict_linear), 3)) print("linear val MSE", round(mse(val_x, val_y, predict_linear), 3)) print("memorizer train MSE", round(mse(train_x, train_y, predict_mem), 3)) print("memorizer val MSE", round(mse(val_x, val_y, predict_mem), 3))
Run to execute this in your browser. Nothing is sent to a server.