# AR example from statsmodels.tsa.ar_model import AutoReg from random import random # contrived dataset data = [x + random() for x inrange(1, 100)] # fit model model = AutoReg(data, lags=1) model_fit = model.fit() # make prediction yhat = model_fit.predict(len(data), len(data)) print(yhat)
# MA example from statsmodels.tsa.arima.model import ARIMA from random import random # contrived dataset data = [x + random() for x inrange(1, 100)] # fit model model = ARIMA(data, order=(0, 0, 1)) # order=(p,d,q) model_fit = model.fit() # make prediction yhat = model_fit.predict(len(data), len(data)) print(yhat)
# ARMA example from statsmodels.tsa.arima.model import ARIMA from random import random # contrived dataset data = [random() for x inrange(1, 100)] # fit model model = ARIMA(data, order=(2, 0, 1)) model_fit = model.fit() # make prediction yhat = model_fit.predict(len(data), len(data)) print(yhat)
# ARIMA example from statsmodels.tsa.arima.model import ARIMA from random import random # contrived dataset data = [x + random() for x inrange(1, 100)] # fit model model = ARIMA(data, order=(1, 1, 1)) model_fit = model.fit() # make prediction yhat = model_fit.predict(len(data), len(data), typ='levels') print(yhat)
# SARIMA example from statsmodels.tsa.statespace.sarimax import SARIMAX from random import random # contrived dataset data = [x + random() for x inrange(1, 100)] # fit model model = SARIMAX(data, order=(1, 1, 1), seasonal_order=(0, 0, 0, 0)) model_fit = model.fit(disp=False) # make prediction yhat = model_fit.predict(len(data), len(data)) print(yhat)
# SARIMAX example from statsmodels.tsa.statespace.sarimax import SARIMAX from random import random # contrived dataset data1 = [x + random() for x inrange(1, 100)] data2 = [x + random() for x inrange(101, 200)] # fit model model = SARIMAX(data1, exog=data2, order=(1, 1, 1), seasonal_order=(0, 0, 0, 0)) model_fit = model.fit(disp=False) # make prediction exog2 = [200 + random()] yhat = model_fit.predict(len(data1), len(data1), exog=[exog2]) print(yhat)
# VAR example from statsmodels.tsa.vector_ar.var_model import VAR from random import random # contrived dataset with dependency data = list() for i inrange(100): v1 = i + random() v2 = v1 + random() row = [v1, v2] data.append(row) # fit model model = VAR(data) model_fit = model.fit() # make prediction yhat = model_fit.forecast(model_fit.y, steps=1) print(yhat)
# VARMA example from statsmodels.tsa.statespace.varmax import VARMAX from random import random # contrived dataset with dependency data = list() for i inrange(100): v1 = random() v2 = v1 + random() row = [v1, v2] data.append(row) # fit model model = VARMAX(data, order=(1, 1)) model_fit = model.fit(disp=False) # make prediction yhat = model_fit.forecast() print(yhat)
# VARMAX example from statsmodels.tsa.statespace.varmax import VARMAX from random import random # contrived dataset with dependency data = list() for i inrange(100): v1 = random() v2 = v1 + random() row = [v1, v2] data.append(row) data_exog = [x + random() for x inrange(100)] # fit model model = VARMAX(data, exog=data_exog, order=(1, 1)) model_fit = model.fit(disp=False) # make prediction data_exog2 = [[100]] yhat = model_fit.forecast(exog=data_exog2) print(yhat)