Machine Learning · Chapter 4 of 40
Training vs Test Data
Split your data into TRAIN (fit the model) and TEST (evaluate honestly). Typical split: 80/20 or 70/30.
Never peek at the test set while iterating — that leaks information and gives false confidence.
Example 1 (python)
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)Reproducible split with random_state.
Example 2 (python)
model.fit(X_train, y_train)
print(model.score(X_test, y_test))Output
0.87Score on unseen data.
Key points
- Always split before training.
- Test set = held-out final evaluation.
- Use random_state for reproducibility.
- Add a validation set for tuning.
💡 Note: For time-series, split by TIME — never randomly. Future can't leak into past.
