Skip to content

Parameter searches: folds used in evaluate_candidates aren't consistent across calls #15149

Open

Description

@NicolasHug

If I use a custom CV iterator with suffle=True, random_state=None, then different folds will be generated for each call to evaluate_candidates().

This isn't an issue for GridSearchCV or RandomizedSearchCV since these only call evaluate_candidates() once. But this is fundamentally wrong for e.g. Successive Halving #13900, which repeatedly call evaluate_candidates but assumes the folds to be always the same (if resource != n_samples). This is even more of an issue if we implement warm start for SH: estimators would not be warmstarted on the same data.

ping in particular @jnothman , I think this is something you noted before (but can't remember where, sorry)?

Activity

  1. jnothman commented on Oct 7, 2019

    @jnothman
    Member

    Yes, I did note this before. (Couldn't point to where.) I'd be happy to see this fixed

  2. NicolasHug commented on Oct 7, 2019

    @NicolasHug
    MemberAuthor

    Do you imagine this fixed by re-working the BaseSearch API (i.e. design something different from evaluate_candidates()), or by e.g. raising an error if the CV has suffle=True, random_state=None? Or even by adopting a more general solution e.g. one that could result from solving #14042 ?

  3. jnothman commented on Oct 7, 2019

    @jnothman
    Member
  4. NicolasHug commented on Oct 7, 2019

    @NicolasHug
    MemberAuthor

    The state is checked in __init__.

    You mean in split()?

  5. jnothman commented on Oct 7, 2019

    @jnothman
    Member
  6. NicolasHug commented on Oct 8, 2019

    @NicolasHug
    MemberAuthor

    If that's not an intended feature by design, we should definitely forbid None and instances then??

  7. jnothman commented on Oct 9, 2019

    @jnothman
    Member
  8. NicolasHug commented on Oct 10, 2019

    @NicolasHug
    MemberAuthor

    Can you expand on "storing the random state"?

    I assume you mean storing a seed coming from the random state at __init__, and then use this seed in split?

    If you mean storing self.random_state = check_random_state(random_state) in __init__, I think the problem is still present.

  9. jnothman commented on Oct 10, 2019

    @jnothman
    Member
  10. NicolasHug commented on Oct 10, 2019

    @NicolasHug
    MemberAuthor

    I'd be happy with that.

  11. thomasjpfan commented on Oct 10, 2019

    @thomasjpfan
    Member

    I would prefer storing the seed. The RandomState.get_state() tuple is quite big (compared to a seed). numpy reference

  12. GaelVaroquaux commented on Oct 30, 2019

    @GaelVaroquaux
    Member

    Why is the fact that different results are returned at each call "fundamentally wrong": the differences are not significant?

    Does not setting the seeds fix the problem?

  13. NicolasHug commented on Oct 30, 2019

    @NicolasHug
    MemberAuthor

    Why is the fact that different results are returned at each call "fundamentally wrong": the differences are not significant?

    Maybe I was over dramatic here, since indeed shuffling the training set should not have a significant impact. However this is definitely a bug when we warm-start SH, which is arguably the main use-case for SH.

    Does not setting the seeds fix the problem?

    Yes, we can "fix" the issue by only allowing ints as random_state in SH. But this is only a band-aid fix to me
    EDIT: actually no, the random_state in SH is only used to sample parameters. We need to set the random_state of the cv to an int instead.

  14. GaelVaroquaux commented on Oct 30, 2019

    @GaelVaroquaux
    Member

    Ok, I get it, it breaks the convergence of successive halving. Sorry for being slow.

    Would changing random_states to be ints in CV objects help?

  15. NicolasHug commented on Oct 30, 2019

    @NicolasHug
    MemberAuthor

    Would changing random_states to be ints in CV objects help?

    That would work too, though I don't think we should prevent users from using a RandomState instance or None. It's convenient to just define an instance at the top of your file and pass it down to each call, e.g. random_state=rng.

  16. GaelVaroquaux commented on Oct 30, 2019

    @GaelVaroquaux
    Member
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