Skip to content

FAQ-D/REF/ENH: use results_class attribute in general #4666

Open

Description

@josef-pkt

When we create a model that inherits the fit method, then it is convenient to have an attribute that tells the super class which results class to use for creating the results instance.
This is convenient if we have to override or add a few methods to the specific Results instance.

  • GenericLikelihoodModel: add option for which results class #2122 was an early issue for GenericLikelihoodModels
  • The discrete count models use it for ZeroInflated model, but uses result_class instead of results_class
  • statespace, GMM and distributed use results_class based on file search
  • RegressionModel.fit does a specific instance check for OLS, isinstance(self, OLS)
    There might be more like this with hardcoded special cases that haven't been changed yet.
  • Some discrete model like Logit, CountModel have a fit method that essentially only creates the correct results instance and otherwise just delegates to the super(...).fit

We also need the results_wrapper_class, which is also used by statespace models
zero inflated count model uses 4 classes, e.g.

        self.result_class = ZeroInflatedPoissonResults
        self.result_class_wrapper = ZeroInflatedPoissonResultsWrapper
        self.result_class_reg = L1ZeroInflatedPoissonResults
        self.result_class_reg_wrapper = L1ZeroInflatedPoissonResultsWrapper

Currently I'm working on subclasses of GLM and some discrete models which should also get an option for results_class. Penalized #4576 currently uses the default Results class without any specific information about the penalization, which needs to be changed.

There are a few more issues or comments in other issues related to this.

So, I think we should add it as general feature for the model classes.

Activity

  1. added this to the 0.10 milestone on May 20, 2018
  2. josef-pkt commented on May 20, 2018

    @josef-pkt
    MemberAuthor

    as a companion

    we might also add the corresponding _results_keys in analogy to _init_keys which would bring us closer to a solution for #2393 (except we still retrofit results instances instead of using keywords)

  3. jbrockmendel commented on May 21, 2018

    @jbrockmendel
    Contributor

    There is precedent in statespace and regime_switching

    As discussed elsewhere (and FUDed to death, obviously, #3877), implementing such a thing can save a ton of duplicated code, in particular in discrete_model. An example of what this can look like.

    Defining these attributes in __init__ is sub-optimal. Too many attributes are already defined in __init__/initialize/_initialize/_handle_data and with layered super calls it is not nearly obvious enough what attributes are defined where. More to the point: the desired Results subclass is class-specific, so should be defined at the class-level .

  4. modified the milestones: 0.10, 0.11 on Feb 1, 2019
  5. modified the milestones: 0.11, josef on Oct 5, 2019
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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions