Train/test split
Hold out part of the data to measure generalisation. Never evaluate on training data.
Code example
from sklearn.model_selection import train_test_split
X_tr, X_te, y_tr, y_te = train_test_split(
X, y, test_size=0.2, random_state=42, stratify=y
)
model.fit(X_tr, y_tr)
print(model.score(X_te, y_te)) # honest evaluation
How it works
If you evaluate a model on the same data it was trained on, you get an over-optimistic score — the model just memorised the answers. The fix: split the data into a training set (e.g. 80%) and a test set (20%). Train on the training set; evaluate on the test set. The test-set score is an honest estimate of how the model will perform on new, unseen data. stratify=y keeps the class balance the same in both splits — important for imbalanced data.
🔍 Where this is used in OpenBenchML
app/routes/benchmark.py — every benchmark does a train/test split before fitting.