Machine Learning

Seed variance: the same model trained ten times

Ten runs identical except for the seed quantify the model's inherent noise: any tuning gain smaller than this variance is indistinguishable from chance — a guardrail to compute once per project.

Prerequisites

lightgbm, scikit-learn, numpy

Python
import numpy as np
from lightgbm import LGBMClassifier
from sklearn.metrics import roc_auc_score

aucs = []
for seed in range(10):
    m = LGBMClassifier(n_estimators=400, learning_rate=0.05,
                       subsample=0.8, subsample_freq=1,
                       random_state=seed, verbose=-1)
    m.fit(X_train, y_train)
    aucs.append(roc_auc_score(y_test, m.predict_proba(X_test)[:, 1]))

aucs = np.array(aucs)
print("AUC par graine :", np.round(aucs, 4))
print(f"moyenne {aucs.mean():.4f} | std {aucs.std():.4f} "
      f"| plage {aucs.max() - aucs.min():.4f}")

Result

AUC par graine : [0.8712 0.8694 0.8731 0.8708 0.8687 0.8725 0.8703
 0.8696 0.8719 0.8741]
moyenne 0.8712 | std 0.0017 | plage 0.0054

Leçon : une « amélioration » de +0.003 d'AUC observée après un tuning
tient dans la plage de bruit de graine (0.0054) — elle ne prouve rien.
Pour comparer deux variantes : moyenner 5 graines de chaque côté,
ou exiger un gain > 3x le std (ici > 0.005).
ReproductibilitéGraineVarianceAUC

Related snippets

Back to the Data Lab