Repository navigation
Conversation
…ataModule build_model() on classifiers, regressors and LSS estimators, and TabularDataModule.__init__ / preprocess_data, defaulted to 101 while the constructors and fit() default to None. build_model() therefore ignored the estimator's own random_state, and an unseeded build_model() was silently seeded with 101. All of them now default to None and resolve it as fit() does: an explicit argument wins, then the estimator's (or the data module's) random_state; with neither, nothing is seeded. A fit that rebuilds (the default) passes the resolved seed explicitly and is unchanged. A fit(rebuild=False) after build_model() keeps the preprocessor that build_model() fitted, now on the constructor seed's partition rather than 101's. build_model() still does not call set_seed(); its docstring now says so.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The constructors and
fit()defaultrandom_statetoNoneand resolve it as "an explicitargument wins over the constructor's; with neither, nothing is reseeded" (#452, #553).
build_model()(classifiers, regressors, LSS) andTabularDataModule.__init__/preprocess_datastill default to101. Sobuild_model()ignores the estimator's own seed:MLPLSS(random_state=42).build_model(...)(docs/core_concepts/sklearn_api.md) splits,preprocesses and orders the loader with
101. An unseededbuild_model()is silently seededwith
101, while an unseededfit()is not.Reproduction
Fix
All of them default to
None, resolved asfit()does: the call'srandom_state, else theestimator's (or, in
preprocess_data, the module's, asval_size=Nonealready falls back tothe module's
val_size); with neither, unseeded.build_model()still does not callset_seed(); its docstring now says so.Behaviour change
rebuild=True, the default) passes the resolved seed explicitly anddraws what it drew before.
build_model()without a seed now uses the constructor'srandom_state, or none, insteadof
101. The two docs examples that call it without a seed now follow the constructor'srandom_state=42:config_system.md(build_model(), then inspecting widths) andsklearn_api.md(build_model(), thenfit(rebuild=False)).build_model()thenfit(rebuild=False)keeps the preprocessor thatbuild_model()fitted, now on the constructor seed's training partition rather than
101's.TabularDataModulewithout a seed is unseeded. Passrandom_state=101tokeep the old behaviour.
Tests
tests/core/test_random_state.py: the defaults;build_model()uses the constructor's seed,and an explicit one wins; unseeded builds pass
random_state=Nonetotrain_test_split;preprocess_datafalls back to the module's seed; a rebuilding fit draws the same validationrows as
build_model(random_state=s);build_model()thenfit(rebuild=False)keeps apreprocessor fitted on the constructor seed's partition. 14 of the 23 cases fail on
main;all pass here.
Docs
The
build_model(),TabularDataModuleandpreprocess_datadocstrings;training_and_evaluation.md("Therandom_stateparameter") andconfig_system.md(thesplit's seed).
Checks
main@ 3f2d149:tests/coreandtests/data: 480 passed, 3 skipped. The new testsfail on
main(14 of 23) and pass here.just check: all hooks passed.just testbefore the rebase (on eb15b6b): 1 failed, 3387 passed, 55 skipped, 28 xfailed;coverage 91.30 %. The failure,
test_retrieval_predictions_in_fresh_process[True-normal-modernnca], also fails onmainhere (Windows, CPU: relative difference 1.698e-06 against
rtol=1e-6).just docs: buildsucceeded.