Skip to content

WIP: Exponential smoothing - #1489

Closed
jseabold wants to merge 39 commits into
statsmodels:masterfrom
jseabold:exponential-smoothing
Closed

jseabold wants to merge 39 commits into
statsmodels:masterfrom
jseabold:exponential-smoothing

Conversation

@jseabold

Copy link
Copy Markdown
Member

This includes #1484 and will need to be rebased on master when that is put into master. This is not close to merging. The only thing that's tested is the ses model. I don't even know how to replicate some of these models yet in R, so this is going to be a longer term project than I'd hoped.

@josef-pkt

Copy link
Copy Markdown
Member

did you look at Hyndman's forecast package?
http://www.inside-r.org/packages/cran/forecast/docs/ets

From my readings I thought that we should get exactly the same versions of the exponential smoothing filters in PR #1287 as in ets

Hyndman has several helpful posts about it in his home page

@jseabold

Copy link
Copy Markdown
Member Author

Yes, I'm using the forecast package. It's in the right ballpark, but there are several subtleties that make this difficult, starting values and timing/alignment in the different cases mostly. I'm just trying to match things now using the heuristic suggested initial values and then move on to optimization (which you must have in some cases for things to be correct).

It's almost all in place, but not quite. It doesn't help that most of the detailed documentation for forecast takes the form of "See Chapter XXX of my book." It's also unhelpful that holt in forecast and HoltWinters from stats give different answers, under what should be the same non-seasonal model. E.g.,

data(co2)
library(forecast)
co2.hw2 <- holt(co2, alpha=.86, beta=.523, initial="simple")
co2.hw <- HoltWinters(co2, alpha=.86, beta=.523, gamma=FALSE)

This suggests that shouldn't be the case, because it's all initial parameters, which are the same, and optimization, which I'm not doing in the former call.

@jseabold

Copy link
Copy Markdown
Member Author

Or to make completely sure they have the same initial values

co2.hw <- HoltWinters(co2, alpha=.86, beta=.523, gamma=FALSE,
                                     l.start=co2.hw2$model$par['l'], 
                                     b.start=co2.hw2$model$par['b'])

I'm missing something...

@josef-pkt

Copy link
Copy Markdown
Member

Fun, fun, fun

Hyndman has his new book online, but I don't know if it's helpful, I never looked at it
https://www.otexts.org/fpp/7

@jseabold

Copy link
Copy Markdown
Member Author

It looks like it's just a question of whether they treat the initial values as pre-sample (holt) or burn them (HoltWinters).

@jseabold

Copy link
Copy Markdown
Member Author

Cleaned up a little bit, fixed some problems, and added test coverage close to 100%. Might still be some corner cases or subtle bugs. There are a few subtle differences in what forecast does depending on if it uses the underlying state-space ets model or not (for initial = 'simple' and non-damped models). We always match the not for now. I mostly noted them in our source, and they're discussed in Hyndman's work. E.g., there are some reparameterizations of the recursions stability during optimization.

TODO

  • pandas wrapper from ENH: Add naive seasonal decomposition function #1484. prefer these to be decorators.
  • docs check / update to make sure it matches recursive equations
  • add to release notes
  • make an example notebook
  • cythonize recursions
  • wrap in optimization framework for initial parameters with constraints. some of the models aren't appropriate if initial starting parameters aren't 'optimal'. e.g., with dampening
  • update initial state condition setting with Hyndman suggestions for optimization
  • squash commits to something sensible. there's not a lot of clean incremental updates on my part.
  • rebase on master when ENH: Add naive seasonal decomposition function #1484 is merged upstream

@jseabold

Copy link
Copy Markdown
Member Author

There's a failure on Python 3 loading the co2 data. Is this a 2to3 problem, a pandas bug, or our bug? Maybe we need a compat wrapper in there for that string?

@jseabold

Copy link
Copy Markdown
Member Author

Re-factored to follow the model-fit-results pattern. Makes using the existing tsa machinery for dates a lot easier as well as doing optimization for the parameters.

@ccsv

ccsv commented Mar 28, 2014

Copy link
Copy Markdown

@jseabold @josef-pkt
Sorry for the late response I had to rearrange some stuff and upgraded to python 3 . I was not able to do the code in Cython I tried but cannot figure how to setup a debugger to use it.
@jseabold
To answer your previous questions from #1287

The code was modified for alignment purposes of two cells because I did not implement backcasting. Secondly the triple exponential smoothing uses the NIST way to calculate the seasons and I did subtraction so that when you put down values like cycle=4 and put something in that is not a multiple of 4 it will go to the closest perfect square allow you to forecast for values such as 15 without problems.

I fixed the 2to3 problem so if you want I can re upload code

Again I apologize for the late response.

@jseabold
jseabold force-pushed the exponential-smoothing branch from 98e94b5 to 8e7450a Compare October 9, 2014 23:04
@ispmarin

Copy link
Copy Markdown

Any news on this front? Can I help somehow? I can't clone the rep right now.

@jseabold

Copy link
Copy Markdown
Member Author

What this needs is for someone to sit down and code the optimization heuristics to help convergence that Hyndman talks about in his book. It's not a ton of work, but it's very much not sexy/fun.

@jseabold

Copy link
Copy Markdown
Member Author

Actually might be worth putting in the new state space framework we have. A decent amount of the code may be able to be re-used but maybe not.

@ispmarin

Copy link
Copy Markdown

Could you please put some pointers in the existing state space framework code?

@jseabold

Copy link
Copy Markdown
Member Author

@jseabold

Copy link
Copy Markdown
Member Author

The tests and dataset can be re-used certainly. I think they may already be in master. This needs a rebase. I'll see about it soon-ish.

@ispmarin

Copy link
Copy Markdown

Great. I'll try to take a look at it after work.

@josef-pkt

Copy link
Copy Markdown
Member

statespace model is so far only linear (and, less relevant, Gaussian)

Can all of the exponential smoothed methods be represented as linear statespace model?

@jseabold

Copy link
Copy Markdown
Member Author

Yes, as far as I recall. The multiplicative error models might need a transformation, but I haven't looked at this in a long time.

@Leoyzen

Leoyzen commented Mar 7, 2016

Copy link
Copy Markdown
Contributor

I've working on a simple case of exponential smoothing based on new SSM, as the same as tbats model of R forecast package.I have no clue how to transform multiplicative version to linear.

@conorbmurphy

Copy link
Copy Markdown

What's the latest on this? I was looking to develop a similar tool before I stumbled across this thread. Will this be incorporated into statsmodels?

@zachmayer

Copy link
Copy Markdown

@Leoyzen Can't you log transform to convert a multiplicative model to linear?

@zachmayer

Copy link
Copy Markdown

What this needs is for someone to sit down and code the optimization heuristics to help convergence that Hyndman talks about in his book. It's not a ton of work, but it's very much not sexy/fun.

@jseabold Where in the book does he talk about optimization heuristics?

@bashtage

Copy link
Copy Markdown
Member

@josef-pkt This has been superseded by released code.

@josef-pkt

Copy link
Copy Markdown
Member

Holt Winters was merged in #4176, released in 0.9.0,
refactored in #4845 for 0.10

@josef-pkt josef-pkt closed this Aug 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants