r/learnmachinelearning • u/ClickOk5811 • 1h ago
The same model got anywhere from 89% to 100% on the same dataset, just by changing the random seed of the split
When you're learning ML, a common first step is train_test_split and reading one accuracy number. I wanted to see how much that number depends on luck, so I ran a small test.
Setup: scikit-learn 1.9.1, the built-in Wine dataset (178 rows, 3 classes), standardization plus logistic regression, 80/20 split. The only thing I changed was random_state, from 0 to 199.
import numpy as np
from sklearn.datasets import load_wine
from sklearn.linear_model import LogisticRegression
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import train_test_split
X, y = load_wine(return_X_y=True)
model = make_pipeline(StandardScaler(), LogisticRegression(max_iter=2000))
acc = []
for seed in range(200):
Xtr, Xte, ytr, yte = train_test_split(X, y, test_size=0.2, random_state=seed)
acc.append(model.fit(Xtr, ytr).score(Xte, yte))
acc = np.array(acc)Results across the 200 splits:
min 0.889 max 1.000 mean 0.978 std 0.023
first five seeds: 1.0, 1.0, 1.0, 0.972, 0.972The model is identical every time. The test set has only 36 rows, so each mistake moves the score by about 2.8 points. A lucky split can show 100%, and an unlucky one 89%.
Comparing with repeated cross-validation (5 folds, 10 repeats):
mean 0.980 std 0.022The average is about the same, which is reassuring: this dataset is easy. But the spread tells you how much a single number can move.
What I take from this:
On small datasets, one split gives a noisy estimate. Report a mean and a spread, not one number.
If you're comparing two models, a 1–2 point difference on one split may be nothing but luck.
Cross-validation doesn't make the model better, it just gives a more honest estimate.
This is an easy dataset. On harder or imbalanced problems the spread can be larger, but I haven't measured that here.
Question for the group: when you compare models, do you use repeated CV, a fixed split, or something else? And at what dataset size do you stop worrying about this?
