Back to playground

How machine learning fits data

-1.32.97.211160246810input (x)output (y)
· drag to zoom · hover for values
Train R²0.01Test R²0.00RMSE2.58

Test R² (on held-out data) is the score that actually matters.

What's happening

A straight line has only one "bend" — none. On this curved pattern it can't follow the shape, so it underfits: training R² is just 0.01. Try a more flexible model.

1 · Make some data

Shape of the pattern

2 · Pick a model

Model type

Tip: click any legend item to show or hide it.

The three things to notice

Underfitting — too simple

A straight line on curved or wavy data can't bend enough to follow the pattern. Training and test error are both high. The model is too rigid.

Overfitting — too flexible

Crank the polynomial degree or tree depth up high. The curve starts wiggling to pass through individual points — training R² climbs toward 1, but test R² drops. It memorized the noise instead of learning the signal.

Generalization — the goal

The best model has training and test scores that are both good and close together. That's the whole game in ML: not fitting the data you have, but predicting the data you don't.

Try this: set the pattern to Steps and compare a curved line against a decision tree — trees shine on sharp, discontinuous jumps, while polynomials fight them. Then set Wavy and watch a random forest smooth out the noise a single deep tree would chase.