Skip to content

Clone method for models? #1841

Closed
Closed

Description

@kshedden

Would it be useful to have a clone method that returns a clean shallow (or deep) copy of a model instance with anything that has been attached during fit stripped off?

I think we are supposed to do this with init_keys, something like this:

init_args = **{k: getattr(old_model, k) for k in old_model.init_keys}
`new_model = GLM(old_model.endog, old_model.exog, init_args)

However some of the more complex models do a lot of pre-processing in init. For example, Cox regression pre-computes a bunch of indices, and GEE categorical (nominal/ordinal) restructures the data using binary indicators. I don't see an easy way to get a clean model instance in these cases without repeating these expensive actions.

A further complication is that some arguments to init, like cov_struct in GEE, are themselves object instances with attributes that may be altered during fit. So these might need their own clone methods.

The use case is meta-procedures like bootstrapping and sensitivity analyses where we need to refit a model many times.

Activity

  1. kshedden commented on Jul 22, 2014

    @kshedden
    ContributorAuthor

    Other possibilities:

    • Don't alter the model during fit
    • Attach a list of properties that are added during fit. Then we can do a shallow copy and delattr the added properties.
  2. josef-pkt commented on Jul 22, 2014

    @josef-pkt
    Member

    this is essentially a duplicate of #1093

  3. josef-pkt commented on Jan 11, 2015

    @josef-pkt
    Member

    closing as duplicate, see 1093

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