How to Lock the Universe
Option 1: Set random_state in sklearn functions (most common)
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.2, random_state=42)
model = RandomForestClassifier(n_estimators=100, random_state=42)
kf = KFold(n_splits=5, shuffle=True, random_state=42)
Option 2: A global seed function (for larger projects)
import random, numpy as np
def set_seed(seed=42):
random.seed(seed)
np.random.seed(seed)
set_seed(42)
Why 42? Tradition (Hitchhiker's Guide to the Galaxy). Any number works!