Repository navigation
Conversation
|
See #1489 for reference |
| try: | ||
| from scipy.special import inv_boxcox | ||
| except ImportError: | ||
| inv_boxcox = lambda x, lam6da: (x**lam6da-1)/lam6da if lam6da != 0 else np.log(x) |
There was a problem hiding this comment.
Yes it is the name of the parameter, I just use a "6" instead of a "b", maybe give it another name?
There was a problem hiding this comment.
I think there are some exampels using either lam or lamda
| "resid", "k"]) | ||
|
|
||
| def holt_winters(data, alpha=None, beta=None, gamma=None, m=None, h=1, trend=None, | ||
| damped=False, seasonal=None, phi=None, optimised=True, |
There was a problem hiding this comment.
I think American English is used in statsmodels.
|
|
||
| def holt_winters(data, alpha=None, beta=None, gamma=None, m=None, h=1, trend=None, | ||
| damped=False, seasonal=None, phi=None, optimised=True, | ||
| boxcoxed=False, remove_bias=False, try_harder=False): |
There was a problem hiding this comment.
try_harder is not a good name.
| Notes | ||
| ----- | ||
| This is a full implementation of the holt winters exponential smoothing as | ||
| per [1]. This includes all the unsatble methods as well as the stable methods. |
| ----- | ||
| This is a full implementation of the holt winters exponential smoothing as | ||
| per [1]. This includes all the unsatble methods as well as the stable methods. | ||
| The implmentaion of the library follows as per the R library as much as possible |
There was a problem hiding this comment.
Did you use the R code? It is not license compatible as far as I know. Or just look at documentation, which is OK.
There was a problem hiding this comment.
No, I never used any R code.
| data : array-like | ||
| Time series | ||
| alpha : float, optional | ||
| The alpha value of the simple exponnetial smoothing, if the value is |
| gamma, m, phi, l0, b0, s0, SSE, level, | ||
| slope, season, opt, AIC, BIC, AICc, resid, k) | ||
|
|
||
| def ses(data, alpha=None, h=1, optimised=True): |
There was a problem hiding this comment.
ses isn't helpful. Maybe simple_exp_smoothing?
| @@ -0,0 +1,96 @@ | |||
| #!/usr/bin/env python3 | |||
There was a problem hiding this comment.
Yeah I realised once the tests had been run, I was going to have to change a few things.
Trying to figure out what the lowest common denominator will be to get this all working.
|
|
||
| class TestHoltWinters(object): | ||
| @classmethod | ||
| def setupClass(cls): |
| return max_seen | ||
| finally: | ||
| warnings.filterwarnings("once") | ||
| def holt_mul_dam(x, xi): |
There was a problem hiding this comment.
This patter of nested function and globals make unit testing really hard since it is difficult to directly test the smallest unit (e.g. a test hat holt_mul_dam works correctly).
|
I only gave it a very quick look so far. |
|
BTW, I think this is a good idea and there is a lot of demand for this type of function, and so, once ready, it should definitely go in. |
1) Stripped all the functions out of the main fucntion 2) Typos etc 3) Tried to find source of backwards compatability issues 4) Changed names of parameters and functions as per request
|
Made the changes as per josef-pkt |
tvanzyl
left a comment
There was a problem hiding this comment.
Completed All Changes
|
I would like to merge this this week, especially because of the high demand for this. |
|
@ChadFulton Sorry, not enough time around exams to tackle all of this. Happy to get the functionality in as I just wanted to have something in a statsmodels release to use in my course next year. |
|
This pull request introduces 2 alerts - view on lgtm.com new alerts:
Comment posted by lgtm.com |
|
The notebook looks very good. (I will add some comments here as a try out a few things in the notebook) aic and similar should be lower case, see eg. RegressionResult about notebook:
|
|
from Chad's comment
I have no idea what any of the Greeks are. Even if we keep those greek letters for now, then they need to be explained somewhere, like a language dictionary. I only checked one docstring and it doesn't mention what each greek parameter stands for. |
josef-pkt
left a comment
There was a problem hiding this comment.
a few review comments for now
| opt = res | ||
| hwfit = self._predict(h=0, alpha=alpha, beta=beta, gamma=gamma, phi=phi, l0=l0, | ||
| b0=b0, s0=s0, use_boxcox=use_boxcox, lamda=lamda, remove_bias=remove_bias) | ||
| hwfit.opt = opt |
There was a problem hiding this comment.
this attaches to the wrapper instance, and should be corrected to
hwfit._results.opt = opt
_results is the original results instance behind the wrapper
also for consistency with other models we should call it mle_retvals instead of opt
| # (s0 + gamma) + (b0 + beta) + (l0 + alpha) + phi | ||
| k = m * seasoning + 2 * trending + 2 + 1 * damped | ||
| AIC = self.nobs * np.log(SSE / self.nobs) + (k) * 2 | ||
| AICc = AIC + (2 * (k + 2) * (k + 3)) / (self.nobs - k - 3) |
There was a problem hiding this comment.
it's just a temp variable here
but we follow lower case for names of objects except classes also for acronyms.
| 'lamda': lamda, | ||
| 'remove_bias': remove_bias} | ||
| hwfit = HoltWintersResults(self, self.params, fittedfcast=fitted, fittedvalues=fitted[:-h - 1], | ||
| fcast=fitted[-h - 1:], SSE=SSE, level=level, |
There was a problem hiding this comment.
I think it's better to rename fcast to fcastvalues in analogy to fittedvalues
(I'm just inspecting a results instance to see what the attributes are.)
| }, | ||
| "outputs": [], | ||
| "source": [ | ||
| "fit1 = ExponentialSmoothing(aust, seasonal_periods=4, trend='add', seasonal='add', use_boxcox=True).fit()\n", |
There was a problem hiding this comment.
incorrect usage
use_boxcox has no effect here.
It took me a while to realize that it has to be a fit keyword.
There was a problem hiding this comment.
removed the **kwargs should ensure we don't let this through in future
|
params is a dict, which is inconsistent with our methods in general. |
| """ | ||
|
|
||
| def __init__(self, endog, trend=None, damped=False, seasonal=None, | ||
| seasonal_periods=None, dates=None, freq=None, missing='none', **kwargs): |
There was a problem hiding this comment.
I think we should remove the **kwargs here. AFAICS, they are not used in this case, and just swallow without feedback any incorrect keywords
| if use_boxcox == 'log': | ||
| lamda = 0.0 | ||
| y = boxcox(data, 0.0) | ||
| elif use_boxcox: |
There was a problem hiding this comment.
this is missing the case when lamda is already a float.
|
general pattern: only the results should know about fit results. having use_boxcox as fit argument and not as model argument might be a bit fragile. I haven't managed yet to think may way through boxcox forecasting in the code. should |
|
general, theoretical question: I was surprised in the plot that seasonal component is not centered at zero. |
Thanks for getting all of this setup. We can move slowly, but we're glad to get it in!
I agree, great! |
|
This pull request introduces 2 alerts - view on lgtm.com new alerts:
Comment posted by lgtm.com |
|
So far, I only looked at the latest changes, and they look good to me. I will try again later today. I think the greek translation should also go in the docstring, either in notes or in explanation for each parameter. It is useful to have the link between statsmodels names and shortcut names used in the reference(s) if there is a dominant reference or consistent Letters/Greeks across references. One thing I think I forgot to mention: Result statistics like aic can go into the results class now. They can be computed lazily on demand, see for example linear_model.RegressionResults. fittedvalues and similar are computed in the fit method and cannot be moved to the results class as in RegressionResults. One more that I did't finish looking at yesterday: Should we already have optimizer options in |
|
To check that the notebook examples work with a different dataset, and it does. The forecast looks good. The only time I needed to spend is on getting the pandas index. with classical airpassenger dataset, which has increasing seasonal amplitude |
|
A I think I'm stopping with reviewing. It seems to work well out of the box and we can add or change things during the next release cycle. |
|
for minimal squashing: "fixed the notebook with the latest changes to the api as requested" on Dec 6 changes to full notebook |
|
I merged the rebased version in PR #4176 @tvanzyl Thanks for this extension, many users will be glad this is in It's open for extensions and some refactoring for the next release. |
|
Awesome! When is the next stable release? :) |
My guess is now mid January. |
Would like to add the holt winters functionality to tsa.
This includes all the additive, multiplicative, trend, damped and seasonal variations.
Also included are two helper functions for Simple Exponential Smoothing and Holt's Trend Method.
Thanks for all your efforts.