時間序列--ARIMA模型的一些引數解釋(cheatsheet)
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/