Skip to content

data leak in GBDT due to warm start #14034

Description

@NicolasHug

(This is about the non-histogram-based version of GBDTs)

X is split into train and validation data with train_test_split(random_state=self.random_state).

As @johannfaouzi noted, in a warm starting context, this will produce a leak if If self.random_state is a RandomState instance: some samples that were used for training in a previous fit might be used for validation now.

I think the right fix would be to raise a ValueError if the provided random state isn't a number and early-stopping is activated

Activity

  1. NicolasHug commented on Jun 7, 2019

    @NicolasHug
    MemberAuthor

    After discussing with @amueller , maybe the best option would be to:

    • store a seed attribute e.g. _train_val_split_seed that would be generated once, the first time fit is called
    • pass this seed as the random_state parameter to train_test_split().
    • add a small test making sure this parameter stays constant between different calls to fit
  2. amueller commented on Jun 7, 2019

    @amueller
    Member

    This should only be done when warm_start is true, though. So different calls to fit without warm start should probably use different splits if random state was None or a random state object.

  3. NicolasHug commented on Jun 7, 2019

    @NicolasHug
    MemberAuthor

    Right.

    The problem is that we allow warm_start to be False the first time we fit, and later set it to true with set_params :(

  4. amueller commented on Jun 7, 2019

    @amueller
    Member

    Sorry, we should always store the seed, but only re-use it if warm_start=True.

  5. jnothman commented on Jun 11, 2019

    @jnothman
    Member

    Why do you prefer to store a seed over get_state()

  6. johannfaouzi commented on Jun 11, 2019

    @johannfaouzi
    Contributor

    At the end of the day, something has to be stored in order to generate the same training and validation sets. An integer is smaller than a tuple returned by get_state(), but the difference can probably be overlooked.

  7. NicolasHug commented on Jun 11, 2019

    @NicolasHug
    MemberAuthor

    If we store a seed we can just directly pass it to train_test_split, avoiding the need to create a new RandomState instance.

    both are fine with me.

  8. ogrisel commented on Sep 13, 2019

    @ogrisel
    Member

    +1 for storing a seed as fit param and reuse that to seed an rng in fit only when warm_start=True.

    AFAIK, np.random.RandomState accept uint32 seed only (between 0 and 2**32 - 1). So the correct way to get a seed from an existing random state object is:

    self.random_seed_ = check_random_state(self.random_state).randint(np.iinfo(np.uint32).max)
  9. johannfaouzi commented on Sep 14, 2019

    @johannfaouzi
    Contributor

    I did something that is not as good for HGBDT:

    self._train_val_split_seed = rng.randint(1024)

    It would probably be worth changing this as well.

    I can work on this if there is no one.

  10. NicolasHug commented on Sep 15, 2019

    @NicolasHug
    MemberAuthor

    PR welcome @johannfaouzi :)

    Also instead of having _small_trainset_seed and _train_val_seed maybe we can just have one single seed. And I just realized that seed should also be passed to the binmapper that will also subsample.

  11. johannfaouzi commented on Sep 19, 2019

    @johannfaouzi
    Contributor

    Hmm this issue was about the non-histogram-based version of GBDTs, so #14999 did not do anything about this. I intentionally did not use keywords so that this issue would not be closed.

    However I've just been starting working on a fix for this issue :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions