Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
Ask Question
I need to calculate
ARIMA
on several values in a loop. All results are obtained successfully, except the one that has values
x = [0, 2]
. Maybe there are two values are too few, but it's part of a loop where the number of values is various, so I can't predict where there are only two values (assuming the problem is that there are two values)
The calculated result is
-9.995715227417712e-06
, and i get this error:
warn('Non-stationary starting autoregressive parameters'
UserWarning: Non-stationary starting autoregressive parameters found. Using zeros as starting parameters.
warnings.warn("Maximum Likelihood optimization failed to "
ConvergenceWarning: Maximum Likelihood optimization failed to converge. Check mle_retvals
I tried to insert any third number into x
([0, 2, 0] or [0, 2, 2], or [0, 2, 3], etc...) and i don't see the error (except for 1, for example x = [0, 2, 1] , which still makes me see the error).
How can I use x = [0, 2]
(just 0 and 2) and correctly calculate the result without seeing the error?
Here's how I'm using ARIMA:
from statsmodels.tsa.arima.model import ARIMA
x = [0, 2]
model = ARIMA(x, order=(1,0,0))
model_fit = model.fit()
forecast = model_fit.forecast(steps=1)
print(forecast[0])
I found a solution, but I'm not 100% sure why it works.
By default trend
is set to 'c', which is constant trend (basically a linear intercept.) If you set it to 'n' or 'ct', the error goes away.
If you set it to 'n', it predict a near-zero value.
If you set it to 'ct', it basically becomes a linear regression, and predicts a point by drawing a straight line through your two points and predicting 4.
Code example:
model = ARIMA(x, order=(1,0,0), trend='ct')
I also got convergence errors when using 'ct' on more than 2 values if those values were in an exactly straight line.
I think this has something to do with the fact that the default settings have three unknowns and two observations, and that would explain why 'n' works, because removing trends reduces it to two parameters. But it doesn't explain why 'ct' works, because that has four parameters.
–
–
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.