'ARIMA model not working properly in new statsmodels ARIMA for python
Earlier I used to use
from statsmodels.tsa.arima_model import ARIMA
model = ARIMA(log_air_passengers, order=(2, 1, 0))
results_AR = model.fit(disp=-1)
plt.plot(log_air_passengers_diff)
plt.plot(results_AR.fittedvalues, color='red')
plt.title('RSS: %.4f'% sum((results_AR.fittedvalues-log_air_passengers_diff)**2))
But now they have a newer version of ARIMA, and the older version will be removed after the 0.12 release. So, I am trying the newer one:
from statsmodels.tsa.arima.model import ARIMA as ARIMA2
model = ARIMA2(log_air_passengers, order=(2, 1, 0), missing='drop')
results_AR = model.fit()
plt.plot(log_air_passengers_diff)
plt.plot(results_AR.fittedvalues, color='red')
plt.title('RSS: %.4f'% sum((results_AR.fittedvalues-log_air_passengers_diff)**2))
And the plot is awry too: But it is not working. I have tried to fiddle around with it but it does not help much. How do I change the code to get it to work?
Solution 1:[1]
You should use SARIMAX
from statsmodels.tsa.statespace.sarimax import SARIMAX
model = SARIMAX(log_air_passengers,order=(1,1,0),simple_differencing=True)
result_AR = model.fit()
plt.plot(log_air_passengers_diff)
plt.plot(result_AR.fittedvalues,color='red')
plt.title('RSS: %.4f'%sum((result_AR.fittedvalues[1:] - log_air_passengers_diff)**2))
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | GENE |