You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
There is an issue calling the predict() method of ARMA object.
Indeed, ARMA object has no k_trend property which is needed in the geterrors() method...
AFAICS, this is a consequence that trend is specified in fit, e.g. #1049
This has never been refactored to avoid initialization code in fit.
So attributes that are initialized or updated in fit like exog and k_trend will not be correct or available.
as workaround you could try to call fit(maxiter=0) before calling geterrors.
I guess we can initiallize k_trend=0 in __init__ and it will be updated in fit
My guess is that we don't do the full refactoring of ARMA/ARIMA anymore, because we most likely will deprecate it in favor of SARIMAX
k_trend, nobs and transparams attributes are initialized in fit.
As a workaround, I set the attributes manually which is not very clean but it works fine...
As for SARIMAX, the predict function seems to be not implemented ( even after calling fit() ).
In definitive, my main concern is that I can't find a way to apply a model fitted for one dataset to an other dataset, but I may have missed something...
What is your specification for constant and trend, given that it is added in fit?
The usecase itself is interesting, and we could try to specifically support it so it works this way.
Initializing k_trend in __init__ looks fine.
I'm not sure a trend should be predicted this way unless it is clear that all time series have the same mean or trend. But it would make sense to use it for the demeaned or detrended series.
(related issue: There was a limitation that exog couldn't contain a constant because it was added through trend, but I don't remember the status)
This would be a good candidate for a cookbook/example notebook.
On Aug 23, 2017, at 1:59 PM, Josef Perktold ***@***.***> wrote:
I thought SARIMAX has an equivalent predict function
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.
(Traveling, so I can't check details) The predict function for SARIMAX is only part of a results object. For ARIMA, I think there is a predict at the model level.
What is your specification for constant and trend, given that it is added in fit ?
I only specify k_trend. For ARMA model, the attribute k_constant is initialized in the __init__() (and can only be 0)
For ARMA, the trend can only be 'nc' -> no constant or 'c' -> with constant, It seems that a trend (linear for exemple) can't be specified.
--> k_constant seems useless for ARMA since the constant is specified with trend.
model_1 = sm.tsa.ARMA(dataset_1, (p, q))
model_1_fitted = model_1.fit(trend='nc') # constant is 0 the dataset is made stationary in
preprocessing
model_2 = sm.tsa.ARMA(dataset_2, (p, q))
model_2.k_trend = model_1.k_trend # = 0
model_2.nobs = len(dataset_2) # not sure it is petinent...
model_2.transparams = False
res = model_2.predict(model_1.params)
For ARIMA, I think there is a predict at the model level.
Yes indeed but same issue than with ARMA if using the predict() without fitting first.
@antvig Can you write some unit tests for this? I would like to know and then have it verified by unit tests which use case works. And a test failure would prevent that it might break during refactoring or changes
e.g. if dataset_2 = data_set_1, then the prediction would be the same.
if k_trend is initialized to zero, then the constant should/might be wrong if it is included in params.
eg. for case dataset_2 = data_set_1 + 1
model_2 .k_trend = model_1 .k_trend
this will be more difficult to support because model_2 has no information about model 1.
Another possibility to check and compare to is model2.fit(maxiter=0):
How much extra time does it use? Does it even work without changing
It recomputes the hessian but it's not an MLE, so inference should be wrong. (?) (valid asymptotic inference might need at least one Markov/Hessian step, if the analogy to constrained estimation works.)
(i.e. inference, prediction confidence intervals would be more work, except prediction confidence intervals ignore parameter uncertainty, AFAIR.)
check this for 0.9.
It sounds like a more serious. We won't do a fit keyword refactoring for 0.9 anymore, but maybe there is a quickfix.
(issue didn't get a label and got lost)
My guess is that we don't do the full refactoring of ARMA/ARIMA anymore, because we most likely will deprecate it in favor of SARIMAX
Or you could "assign" it to a maintainer who has volunteered to clean it up #3992.
new general design principle
This is a problem that comes up a ton in tsa models because k_trend/k_ar... don't get set in FooModel.__init__. I think the solution is to have a model-parent class for these models; something like:
and have ARMA set the expected attributes in __init__ so as to conform to the patterns in the broader code-base. model-selection type methods would belong in this type of parent class.
Adding a new super class or intermediate class into the class hierarchy is a different issue.
The simple fix is to finish moving all data and specification arguments to __init__ and deprecate those in fit.
(ARIMA delegates to ARMA, and that created or creates other sources of bugs.)
In general spawn, class factory or class dispatch, didn't catch on in our design, e.g. #842
In my experience it is too confusing (as a user).
Adding a new super class or intermediate class into the class hierarchy is a different issue.
Fair enough. I don't expect any movement on this front anytime soon.
BTW I forgot to mention from a different thread: here's to a speedy recovery for your kid.
The simple fix is to finish moving all data and specification arguments to __init__ and deprecate those in fit.
(ARIMA delegates to ARMA, and that created or creates other sources of bugs.)
Looks like ARMA.__init__ sig is (self, endog, order, exog=None,... So flip the exog/order, add some validation+warnings for the change, move trend kwarg from fit to __init__... roughly the same for ARIMA and AR... updating a bunch of tests. (conceivably extend to VAR though I'd be reticent to do this in one go). The amount of labor sounds roughly Topic Week sized yah?
Activity
josef-pkt commentedon Aug 23, 2017
AFAICS, this is a consequence that trend is specified in
fit, e.g. #1049This has never been refactored to avoid initialization code in
fit.So attributes that are initialized or updated in fit like exog and k_trend will not be correct or available.
as workaround you could try to call
fit(maxiter=0)before calling geterrors.I guess we can initiallize k_trend=0 in
__init__and it will be updated infitMy guess is that we don't do the full refactoring of ARMA/ARIMA anymore, because we most likely will deprecate it in favor of SARIMAX
antvig commentedon Aug 23, 2017
This issue prevents from applying a fitted model on a new dataset :
k_trend, nobs and transparams attributes are initialized in fit.
As a workaround, I set the attributes manually which is not very clean but it works fine...
As for SARIMAX, the predict function seems to be not implemented ( even after calling fit() ).
In definitive, my main concern is that I can't find a way to apply a model fitted for one dataset to an other dataset, but I may have missed something...
josef-pkt commentedon Aug 23, 2017
What is your specification for constant and trend, given that it is added in fit?
The usecase itself is interesting, and we could try to specifically support it so it works this way.
Initializing k_trend in
__init__looks fine.I'm not sure a trend should be predicted this way unless it is clear that all time series have the same mean or trend. But it would make sense to use it for the demeaned or detrended series.
(related issue: There was a limitation that exog couldn't contain a constant because it was added through trend, but I don't remember the status)
This would be a good candidate for a cookbook/example notebook.
josef-pkt commentedon Aug 23, 2017
I thought SARIMAX has an equivalent predict function
ChadFulton commentedon Aug 23, 2017
antvig commentedon Aug 24, 2017
I only specify k_trend. For ARMA model, the attribute k_constant is initialized in the
__init__()(and can only be 0)For ARMA, the trend can only be 'nc' -> no constant or 'c' -> with constant, It seems that a trend (linear for exemple) can't be specified.
--> k_constant seems useless for ARMA since the constant is specified with trend.
Yes indeed but same issue than with ARMA if using the predict() without fitting first.
[-]ARMA.geterrors()[/-][+]ARMA.predict()[/+]josef-pkt commentedon Aug 24, 2017
@antvig Can you write some unit tests for this? I would like to know and then have it verified by unit tests which use case works. And a test failure would prevent that it might break during refactoring or changes
e.g. if dataset_2 = data_set_1, then the prediction would be the same.
if k_trend is initialized to zero, then the constant should/might be wrong if it is included in params.
eg. for case dataset_2 = data_set_1 + 1
this will be more difficult to support because model_2 has no information about model 1.
Another possibility to check and compare to is model2.fit(maxiter=0):
How much extra time does it use? Does it even work without changing
It recomputes the hessian but it's not an MLE, so inference should be wrong. (?) (valid asymptotic inference might need at least one Markov/Hessian step, if the analogy to constrained estimation works.)
(i.e. inference, prediction confidence intervals would be more work, except prediction confidence intervals ignore parameter uncertainty, AFAIR.)
ChadFulton commentedon Aug 24, 2017
As long as the model specifications are identical (i.e. identical p, d, q and trend), you can always do:
Note that trend uses
ninstead ofnc, since it allows a more general trend than a constant.antvig commentedon Sep 12, 2017
Hi,
I'm not really familiar with unit test but here is two tests i wrote:
Test if ARMA.predict and ARMAResults.predict produce the same prediction if they have the same attributes
Test if ARMA.predict can be applied on a dataset with params from a model fitted on an other dataset
unit_test.zip
josef-pkt commentedon Oct 7, 2017
check this for 0.9.
It sounds like a more serious. We won't do a fit keyword refactoring for 0.9 anymore, but maybe there is a quickfix.
(issue didn't get a label and got lost)
prio-high to check at least how serious this is
6 remaining items
jbrockmendel commentedon Oct 17, 2017
Or you could "assign" it to a maintainer who has volunteered to clean it up #3992.
This is a problem that comes up a ton in tsa models because k_trend/k_ar... don't get set in
FooModel.__init__. I think the solution is to have a model-parent class for these models; something like:and have
ARMAset the expected attributes in__init__so as to conform to the patterns in the broader code-base. model-selection type methods would belong in this type of parent class.josef-pkt commentedon Oct 17, 2017
Adding a new super class or intermediate class into the class hierarchy is a different issue.
The simple fix is to finish moving all data and specification arguments to
__init__and deprecate those infit.(ARIMA delegates to ARMA, and that created or creates other sources of bugs.)
In general
spawn, class factory or class dispatch, didn't catch on in our design, e.g. #842In my experience it is too confusing (as a user).
jbrockmendel commentedon Oct 17, 2017
Fair enough. I don't expect any movement on this front anytime soon.
BTW I forgot to mention from a different thread: here's to a speedy recovery for your kid.
Looks like
ARMA.__init__sig is(self, endog, order, exog=None,...So flip the exog/order, add some validation+warnings for the change, movetrendkwarg fromfitto__init__... roughly the same for ARIMA and AR... updating a bunch of tests. (conceivably extend to VAR though I'd be reticent to do this in one go). The amount of labor sounds roughly Topic Week sized yah?ENH/BUG: Add check to AR and ARMA instance to prevent bugs
ENH/BUG: Add check to AR and ARMA instance to prevent bugs
ENH/BUG: Add check to AR and ARMA instance to prevent bugs
ENH/BUG: Add check to AR and ARMA instance to prevent bugs
ENH/BUG: Add check to AR and ARMA instance to prevent bugs
ENH/BUG: Add check to AR and ARMA instance to prevent bugs
ENH/BUG: Add check to AR and ARMA instance to prevent bugs
ENH/BUG: Add check to AR and ARMA instance to prevent bugs