Skip to content

[MRG] Using one single random seed for warm start in HGBDT - #14999

Merged
NicolasHug merged 6 commits into
scikit-learn:masterfrom
johannfaouzi:warm_start_seed_HGBDT
Sep 19, 2019
Merged

NicolasHug merged 6 commits into
scikit-learn:masterfrom
johannfaouzi:warm_start_seed_HGBDT

Conversation

@johannfaouzi

Copy link
Copy Markdown
Contributor

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) and self._train_val_split_seed = rng.randint(1024) have been replaced with self._random_seed = rng.randint(np.iinfo(np.uint32).max) (@ogrisel comment)

  • The random seed is passed to the bin mapper (@NicolasHug comment). The rng parameter in the _bin_data is removed since it is not used, and we pass the rng parameter to BinMapper two 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

@johannfaouzi johannfaouzi changed the title Using one single random seed for warm start in HGBDT [MRG] Using one single random seed for warm start in HGBDT Sep 17, 2019

@ogrisel ogrisel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@NicolasHug NicolasHug left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for completeness let's refit gb_1 and assert that the seed is different here

@johannfaouzi johannfaouzi Sep 18, 2019 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as a nit a == b == c works as expected in Python

@johannfaouzi

Copy link
Copy Markdown
Contributor Author

I updated the comment for warm starting and cleaned up the corresponding test with your suggestions.

@NicolasHug
NicolasHug merged commit 78c06e5 into scikit-learn:master Sep 19, 2019
@NicolasHug

NicolasHug commented Sep 19, 2019 •

Copy link
Copy Markdown
Member

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

@johannfaouzi
johannfaouzi deleted the warm_start_seed_HGBDT branch September 19, 2019 14:23
davidgegiya added a commit to davidgegiya/agent-orchestrator that referenced this pull request Nov 8, 2026
Pin d2476fb679f05e80c56e8b151ff0f6d7a470e4ae and its regression selectors for reproducible runs.

Source: scikit-learn/scikit-learn#14999
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

data leak in GBDT due to warm start

3 participants