Skip to content

Common tests: Check that random_state is not altered #1108

Closed

Description

@amueller

Not sure this is what we want, but I think it is:
fit should not change the random_state so that fitting twice on the same data set should produce the same result.
There was a comment by @ogrisel in #455 along these lines, I think.

Activity

  1. ogrisel commented on Sep 3, 2012

    @ogrisel
    Member

    +1 but this will have a very wide impact.

  2. amueller commented on Sep 3, 2012

    @amueller
    MemberAuthor

    Yeah, this is gonna be real fun ^^

  3. ogrisel commented on Sep 3, 2012

    @ogrisel
    Member

    We should probably change the current fit idiom:

    self.random_state = check_random_state(self.random_state)
    

    to:

    self.random_state_ = random_state = check_random_state(self.random_state)
    

    and use that one instead in fit. That would also require pass random_state=0 (fixed seed) in the constructors of all the randomized estimators. Some people might not like it...

  4. amueller commented on Sep 3, 2012

    @amueller
    MemberAuthor

    Why do you want to make random_state_ an attribute? It only needs to be local to fit. If you need another random state somewhere else, why not generate it again from the self.random_state?

    I'm -1 on fixing seeds by default.

  5. GaelVaroquaux commented on Sep 3, 2012

    @GaelVaroquaux
    Member

    +1 but this will have a very wide impact.

    +1

  6. GaelVaroquaux commented on Sep 3, 2012

    @GaelVaroquaux
    Member

    Why do you want to make random_state_ an attribute? It only needs to be
    local to fit. If you need another random state somewhere else, why not
    generate it again from the self.random_state?

    GMMs and HMMs can use it to sample observations from the model. People
    expect that sampling twice will give them different observations.

  7. ogrisel commented on Sep 3, 2012

    @ogrisel
    Member

    I'm -1 on fixing seeds by default.

    Indeed, this is not a requirement.

    GMMs and HMMs can use it to sample observations from the model. People
    expect that sampling twice will give them different observations.

    I don't think so. The sampling method should have it's own random_state kwargs to make that controllable.

  8. amueller commented on Sep 3, 2012

    @amueller
    MemberAuthor

    I agree with @ogrisel on the hmm issue.
    About self.random_state_: I don't like this duplication of attributes for the sake of not changing the model.
    I think it becomes pretty confusing to distinguish the two. I know we use this in some places and it can not always be avoided, but I think we should try.

  9. ogrisel commented on Sep 3, 2012

    @ogrisel
    Member

    If you want idem potent fit calls you need to remember the original seed somewhere. But this is actually not the random_state itself that should be stored, but an integer seed. I think we should write a use case for the API caller point of view before moving on with this discussion.

  10. amueller commented on Sep 3, 2012

    @amueller
    MemberAuthor

    agreed :)

  11. glouppe commented on Sep 4, 2012

    @glouppe
    Contributor

    To avoid confusion, we may rename random_state to seed in the constructors and then set random_state = check_random_state(self.seed) (or self.random_state_ = ... if it needs to be stored) in `fit? Too bad this would break the current API though... :(

  12. mblondel commented on Oct 15, 2012

    @mblondel
    Member

    +1 for not overwriting self.random_state

    PR #1200 had this problem too.

  13. amueller commented on Feb 13, 2013

    @amueller
    MemberAuthor

    Closed by #1518 and #1670.

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