You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Parameter searches: folds used in evaluate_candidates aren't consistent across calls #15149
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)?
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 ?
Also related is the fact that without a fit method, splitters behave
surprisingly with random_state when compared to estimators: The state is
checked in __init__.
At the time the splitters were given this general design, we found
ourselves inconsistent and chose this as the safest policy without
redesigning the API.
Only allowing int is one solution. Storing the random state is another.
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.
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.
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.
I would not mind erroring on this with a good error message.
Activity
jnothman commentedon Oct 7, 2019
Yes, I did note this before. (Couldn't point to where.) I'd be happy to see this fixed
NicolasHug commentedon Oct 7, 2019
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 hassuffle=True, random_state=None? Or even by adopting a more general solution e.g. one that could result from solving #14042 ?jnothman commentedon Oct 7, 2019
NicolasHug commentedon Oct 7, 2019
You mean in
split()?jnothman commentedon Oct 7, 2019
NicolasHug commentedon Oct 8, 2019
If that's not an intended feature by design, we should definitely forbid None and instances then??
jnothman commentedon Oct 9, 2019
NicolasHug commentedon Oct 10, 2019
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 insplit?If you mean storing
self.random_state = check_random_state(random_state)in__init__, I think the problem is still present.jnothman commentedon Oct 10, 2019
NicolasHug commentedon Oct 10, 2019
I'd be happy with that.
thomasjpfan commentedon Oct 10, 2019
I would prefer storing the seed. The
RandomState.get_state()tuple is quite big (compared to a seed). numpy referenceGaelVaroquaux commentedon Oct 30, 2019
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?
NicolasHug commentedon Oct 30, 2019
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.
Yes, we can "fix" the issue by only allowing ints as
random_statein SH. But this is only a band-aid fix to meEDIT: 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.
GaelVaroquaux commentedon Oct 30, 2019
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?
NicolasHug commentedon Oct 30, 2019
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.GaelVaroquaux commentedon Oct 30, 2019