Here's a trap. If you train a model on some data and then test it on the same data, of course it does well — it has effectively seen the answers. That tells you nothing about how it will cope with the future. So we always split the data into two parts:
The test set is a stand-in for "new data the model has never seen." Performance there is the only honest measure of how good the model really is.
The line is fitted using only the training points. Toggle to reveal the test points — held out during training — and see how well the line predicts them. A model that does well on data it never trained on is one you can trust.
Never let the test set leak into training. The moment a model has peeked at the
test data — even indirectly, through choices you made — your score is inflated and meaningless.
Keeping a clean, untouched test set is the single most important discipline in applied machine
learning, and it's what makes the next idea,