Skip to content

REF DRYing fit methods #1615

Closed
Closed

Description

@josef-pkt

It looks like we are adding or copying many fit functions just because they need to choose the results class. In some cases they also have special code to calculate start_params.

Two possibilities

  • register return class in a module global, as alternative it could be another attribute
  • add method for start_params()

similar use case:
currently it's not possible to subclass the results class without also subclasses the model and overwriting fit,
example: least squares (WLS) with predefined scale, scipy curve_fit discussion, and Stata's vwls which would need to redefine results.scale
(I just realized that I could pick this up as option for cov_type)

(while looking at the missing NegativeBinomial.fit_regularized #1454)

Activity

  1. added a commit that references this issue on Apr 22, 2014
    8235c42
  2. josef-pkt commented on May 30, 2014

    @josef-pkt
    MemberAuthor

    I'm running into this again for adding another fit_method ( fit_constrained)

    example Logit.fit

        def fit(self, start_params=None, method='newton', maxiter=35,
                full_output=1, disp=1, callback=None, **kwargs):
            bnryfit = super(Logit, self).fit(start_params=start_params,
                    method=method, maxiter=maxiter, full_output=full_output,
                    disp=disp, callback=callback, **kwargs)
            discretefit = LogitResults(self, bnryfit)
            return BinaryResultsWrapper(discretefit)
        fit.__doc__ = DiscreteModel.fit.__doc__
    

    and Poisson.fit

        def fit(self, start_params=None, method='newton', maxiter=35,
                full_output=1, disp=1, callback=None, **kwargs):
            cntfit = super(CountModel, self).fit(start_params=start_params,
                    method=method, maxiter=maxiter, full_output=full_output,
                    disp=disp, callback=callback, **kwargs)
            discretefit = PoissonResults(self, cntfit)
            return PoissonResultsWrapper(discretefit)
        fit.__doc__ = DiscreteModel.fit.__doc__
    

    The only difference is in the Results and ResultsWrapper classes

  3. jseabold commented on May 30, 2014

    @jseabold
    Member

    Yes, this was part of the refactor that moved these into types of discrete choice models since the return classes have a lot of model-specific code.

    I'm +1 on a _start_params method. I'd be +.5 on some magic to specify the return class, but it sounds like more trouble than it's going to be worth IMO. Would make things significantly more complicated.

  4. added a commit that references this issue on Jul 22, 2014
    cb1795e
  5. added a commit that references this issue on Sep 2, 2014
    8171198
  6. added 2 commits that reference this issue on Oct 23, 2014
    18a1faa
    8f2ab7a
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