Skip to content

REF/Review: holtwinters Results pattern, inconsistent ? #5256

Closed

Description

@josef-pkt

I am trying to add cached properties fittedvalues and resid generically to base.model.Results in 5255

holtwinters uses attributes instead of cached properties
I get one test failure after adding the generic methods in all environments
https://travis-ci.org/statsmodels/statsmodels/jobs/432552696

    def test_direct_holt_add():
        mod = SimpleExpSmoothing(housing_data)
        res = mod.fit()
        x = np.squeeze(np.asarray(mod.endog))
        alpha = res.params['smoothing_level']
        l, b, f, err, xhat = _simple_dbl_exp_smoother(x, alpha, beta=0.0,
                                                      l0=res.params['initial_level'], b0=0.0,
                                                      nforecast=5)
    
        assert_allclose(l, res.level)
        assert_allclose(f, res.level.iloc[-1] * np.ones(5))
        assert_allclose(f, res.forecast(5))
    
        mod = ExponentialSmoothing(housing_data, trend='add')
        res = mod.fit()
        x = np.squeeze(np.asarray(mod.endog))
        alpha = res.params['smoothing_level']
        beta = res.params['smoothing_slope']
        l, b, f, err, xhat = _simple_dbl_exp_smoother(x, alpha, beta=beta,
                                                      l0=res.params['initial_level'],
                                                      b0=res.params['initial_slope'], nforecast=5)
    
>       assert_allclose(xhat, res.fittedvalues)
E       AssertionError: 
E       Not equal to tolerance rtol=1e-07, atol=0
E       
E       (shapes (714,), (1,) mismatch)
E        x: array([ 96.199944,  96.221455,  99.021455, 127.721455, 150.821455,
E              152.521455, 147.821455, 148.121455, 138.221455, 136.421455,
E              120.021455, 104.721455,  95.621455,  86.021455,  90.721455,...
E        y: array([111.521455])

I have no idea yet what's going on.

Activity

  1. josef-pkt commented on Sep 25, 2018

    @josef-pkt
    MemberAuthor

    the problem is the res.predict() only returns one observation instead of a nobs array.

    Also, AFAIK, assigning attributes does not overwrite inherited cached properties. (IIRC we have that problem in RegressionResults scale)
    this means we have to add cached properties explicitly override the inherited method.
    e.g. we could use plain property with internally assigned _fittedvalues

    Bug/convention: I think predict should follow standard pattern and return full nobs array.
    holtwinters Results classes has a forecast method which defaults to a single one step forecast identical to predict.

    Also the holtwinters classes still compute post estimation results like sse/ssr, aic in fit instead of in results class
    results is computed in fit following standard definition, but not used in fit.

  2. josef-pkt commented on Sep 25, 2018

    @josef-pkt
    MemberAuthor

    running pytest holtwinter.py shows also 5 convergence warnings.
    If those are expected, then they should be silenced, otherwise investigated for improvements.

    about resid
    There are no unit tests, and resid = endog - fittedvalues is not true if fit option remove_bias=True, because the resid.mean() is subtracted in fitted which is fittedvalues concatenated with forecast, but resid attribute is not debiased.

    I'm making some small changes in #5255 without the refactoring of moving more post estimation results from fit to results methods.

    • rename attribute to _fittedvalues and add property fittedvalues
    • rename resid to resid_biased and let HoltWintersResults.resid be the, new in 5255, cached attribute from base.Results which satisfies resid = endog - fittedvalues
  3. bashtage commented on Jul 30, 2026

    @bashtage
    Member

    The holtwinters module has been fully rewritten since this review was filed: Results now uses explicit _fittedvalues/_resid-backed properties (no more cached-property masking) and predict() returns a proper array, resolving both original complaints. Closing as superseded by the rewrite. Note: one narrow issue survives - HoltWintersResults.resid still does not equal endog - fittedvalues when fit(remove_bias=True) is used (statsmodels/tsa/holtwinters/model.py computes resid before the debiasing adjustment) - happy to file that as its own focused issue if useful.

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