1.solver:采用哪一种收敛算法(不建议更改
2.disp:True会打印中间过程,我们直接设置False即可
3.transparam:默认是True,建议选择true
Whether or not to transform the parameters to ensure stationarity. Uses the transformation suggested in Jones (1980). If False, no checking for stationarity or invertibility is done.
4.trend:=‘c'表示加一个截距项,=’nc‘表示不加截距项
举个例子
from pandas import read_csv
from pandas import datetime
from matplotlib import pyplot
from statsmodels.tsa.arima_model import ARIMA
from sklearn.metrics import mean_squared_error
from math import sqrt
# load dataset
def parser(x):
return datetime.strptime('190'+x, '%Y-%m')
series = read_csv('shampoo-sales.csv', header=0, parse_dates=[0], index_col=0, squeeze=True, date_parser=parser)
# split into train and test sets
X = series.values
size = int(len(X) * 0.66)
train, test = X[0:size], X[size:len(X)]
history = [x for x in train]
predictions = list()
# walk-forward validation
for t in range(len(test)):
# fit model
model = ARIMA(history, order=(4,1,0))
model_fit = model.fit(disp=False, trend='c')
print(model_fit.params)
# one step forecast
yhat = model_fit.forecast()[0]
# store forecast and ob
predictions.append(yhat)
history.append(test[t])
# evaluate forecasts
rmse = sqrt(mean_squared_error(test, predictions))
print('Test RMSE: %.3f' % rmse)
from pandas import read_csv
from pandas import datetime
from matplotlib import pyplot
from statsmodels.tsa.arima_model import ARIMA
from sklearn.metrics import mean_squared_error
from math import sqrt
# load dataset
def parser(x):
return datetime.strptime('190'+x, '%Y-%m')
series = read_csv('shampoo-sales.csv', header=0, parse_dates=[0], index_col=0, squeeze=True, date_parser=parser)
# split into train and test sets
X = series.values
size = int(len(X) * 0.66)
train, test = X[0:size], X[size:len(X)]
history = [x for x in train]
predictions = list()
# walk-forward validation
for t in range(len(test)):
# fit model
model = ARIMA(history, order=(4,1,0))
model_fit = model.fit(disp=False, trend='nc')
print(model_fit.params)
# one step forecast
yhat = model_fit.forecast()[0]
# store forecast and ob
predictions.append(yhat)
history.append(test[t])
# evaluate forecasts
rmse = sqrt(mean_squared_error(test, predictions))
print('Test RMSE: %.3f' % rmse)
加截距项的结果:
...
[ 11.42283717 -1.16087885 -0.6519841 -0.547411 -0.28820764]
[ 11.75656838 -1.11443479 -0.61607471 -0.49084722 -0.24452864]
[ 11.40486702 -1.11705478 -0.65344924 -0.50213939 -0.25677931]
Test RMSE: 81.545
不加截距项的结果:
...
[-0.90717131 -0.22332019 -0.11240858 -0.04008561]
[-0.88836083 -0.21098412 -0.09046333 -0.02121404]
[-0.89260136 -0.24120301 -0.10243393 -0.03165432]
Test RMSE: 95.061
选哪一个有你自己决定
https://machinelearningmastery.com/tune-arima-parameters-python/
这一个文章有时序经典各种模型的cheatsheethttps://machinelearningmastery.com/time-series-forecasting-methods-in-python-cheat-sheet/