Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
josef-pkt opened this issue Sep 25, 2018 · 2 comments
Open

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

josef-pkt opened this issue Sep 25, 2018 · 2 comments

Comments

@josef-pkt
Copy link
Member

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.

@josef-pkt
Copy link
Member Author

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.

@josef-pkt
Copy link
Member Author

josef-pkt commented Sep 25, 2018

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

@bashtage bashtage added this to bugs in 0.11 Jul 15, 2019
@bashtage bashtage removed this from Bugs (Not-started ) in 0.11 Jan 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant