← Learning Hub
Beginner

Training, Testing and Measuring Accuracy

A model can simply memorise its examples. To know if it really learned, keep some data hidden, then test on it. This is the train/test split.

A model that scores perfectly on the data it learned from may have just memorised it. Testing on unseen data is the only honest way to know how it will behave in the real world. Picking the right metric matters too - accuracy can be misleading.

Example
You can edit this code.

Measuring a classifier

Example
You can edit this code.

Overfitting

Overfitting = great on training data, poor on new data (it memorised). Underfitting = poor on both (too simple). Always judge a model on data it hasn't seen.

Accuracy can fool you. If only 1 in 100 payments is fraud, a model that always says "not fraud" is 99% accurate - and useless. Look at the confusion matrix, precision and recall too.
Key points
  • Keep a test set the model never trains on.
  • MAE and R² for regression; accuracy and confusion matrix for classification.
  • Watch for overfitting.

📝 Test yourself

1. Why keep a test set?
2. Great on training data but poor on new data is called...
3. Fill in the function that splits data:
from sklearn.model_selection import