Repository navigation
[MRG] Using one single random seed for warm start in HGBDT - #14999
Conversation
NicolasHug
left a comment
There was a problem hiding this comment.
Thanks a lot for the PR @johannfaouzi !
Some minor nitpicks but LGTM
| @@ -105,11 +105,10 @@ def fit(self, X, y): | |||
| y = self._encode_y(y) | |||
|
|
|||
| # The rng state must be preserved if warm_start is True | |||
There was a problem hiding this comment.
that comment is outdated. Maybe replace with e.g.:
When warm starting, we want to re-use the same seed that was used the first time fit was called (e.g. for subsampling or for the train/val split).
| gb_1.fit(X, y) | ||
| train_val_seed_1 = gb_1._train_val_split_seed | ||
| small_trainset_seed_1 = gb_1._small_trainset_seed | ||
| random_seed_1 = gb_1._random_seed |
There was a problem hiding this comment.
for completeness let's refit gb_1 and assert that the seed is different here
There was a problem hiding this comment.
There is still a small chance (2 ** -32) that the seeds are equal. Let's hope that it never happens :)
The seeds will be equal when the random state is an integer. They will only be different (with high probability) when the random seed is a RandomState instance (because it will be mutated) or None.
There was a problem hiding this comment.
Actually never mind I think it's expected that the seed will be equal anyway since we pass an int and a fixed instance as random_state. I guess we should pass None instead?
|
|
||
| assert train_val_seed_2 == train_val_seed_3 | ||
| assert small_trainset_seed_2 == small_trainset_seed_3 | ||
| assert random_seed_1 == random_seed_2 |
There was a problem hiding this comment.
as a nit a == b == c works as expected in Python
|
I updated the comment for warm starting and cleaned up the corresponding test with your suggestions. |
|
Thanks a lot @johannfaouzi ! Not sure whether that needs a whats new (I would say no considering the very minimal impact on predictions that this could have). Merging anyway |
Pin d2476fb679f05e80c56e8b151ff0f6d7a470e4ae and its regression selectors for reproducible runs. Source: scikit-learn/scikit-learn#14999
Reference Issues/PRs
Discussion from #14034. This PR is for the histogram-based version of GBDT.
What does this implement/fix? Explain your changes.
One single random seed is used instead of several ones. It is needed to save it for warm starting, so that every time there is some sort of RNG, the same seed is used.
self._small_trainset_seed = rng.randint(1024)andself._train_val_split_seed = rng.randint(1024)have been replaced withself._random_seed = rng.randint(np.iinfo(np.uint32).max)(@ogrisel comment)The random seed is passed to the bin mapper (@NicolasHug comment). The
rngparameter in the _bin_data is removed since it is not used, and we pass therngparameter toBinMappertwo lines above.Any other comments?
When we have a version of warm starting that is good enough for HGBDT, I will try to do the same for GBDT (i.e. fix #14034).
Possible reviewers: @NicolasHug @ogrisel