Reproducibility depends on the stability of the inputs passed to probatus modules. Follow these guidelines for common inputs:
Static Dataset
Ensure the input dataset X and y do not change. If generating synthetic data (e.g., using sklearn.datasets.make_classification), always set the random_state.
Static Data Splits
- Train/Test Splits: When using
sklearn.model_selection.train_test_split, set the random_state. - Cross-Validation (CV): If you pass an integer to the
cv parameter in probatus, the module's internal random_state will handle the splitting. However, if you pass a custom CV generator object (like StratifiedKFold), you must set the random_state within that object itself.
Static Classifier
- If the module requires a not-fitted classifier, set the
random_state on the classifier instance. - If the classifier must be pre-fitted, ensure the training process itself is reproducible by setting the model's
random_state.
Static Hyperparameter Tuning
When using modules that perform optimization (e.g., ShapRFECV), ensure the search object (like RandomizedSearchCV) has a fixed random_state. This ensures the same parameter permutations are explored in every round. If the search space generation is stochastic, set its random_state as well.
from sklearn.model_selection import StratifiedKFold, train_test_split
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import RandomizedSearchCV
# 1. Static train/test split
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42)
# 2. Static CV settings
cv2 = StratifiedKFold(n_splits=5, shuffle=True, random_state=42)
# 3. Static classifier
model = RandomForestClassifier(random_state=42)
# 4. Static search CV for hyperparameter tuning
param_grid = {"n_estimators": [5, 7, 10], "max_leaf_nodes": [3, 5, 7, 10]}
search = RandomizedSearchCV(model, param_grid, n_iter=1, random_state=42)