自回归模型,过去的观察值和现在的干扰值的联系组合预测
滑动平均模型, 过去的感染治和现在的干扰值的线性组合预测
ARMA(Autoregressive–moving-average model)
Wiki
ARIMA(p,d,q) ,非平稳序列经过k阶差分后变成平稳序列运用ARMA模型
绘制时序图看看数据长什么样,猜测是平稳还是非平稳
ADF(Augmented Dickey-Fuller unit root test)单位根平稳检验
随机序列(白噪声)检验
方法:Q统计量、LB统计量
绘制ACF(Autocorrelation)自相关图,自相关系数
PACF(Partial Autocorrelation)偏自相关图,
BIC信息量最小选择p,q
p, q 阶数一般不超过length/10
模型检验和参数估计
ARIMA模型预测
拖尾:始终有非零取值,不会在k大于某个常数后就恒等于零(或在0附近随机波动)
截尾:在大于某个常数k后快速趋于0为k阶截尾
statsmodels
Time Series analysis
ARIMA
import statsmodels.api as smimport pandas as pddf = pd.DataFrame(data)#dataframex = #LOAD YOUR DATAindex = pd.Index(sm.tsa.datetools.dates_from_range('1959Q1', '2009Q3'))#ordates = sm.tsa.datetools.dates_from_range('1980m1', length=nobs)df = pd.DataFrame(X,colomns=['x'],index=index)#plotdf.plot(df)#ACFsm.tsa.acf(df)sm.graphics.tsa.plot_acf(df)#PACFsm.tsa.pacf(df)sm.graphics.tsa.plot_pacf(df)#ADFsm.tsa.adfuller(df.x) #df.loc[:,'x'] | df.iloc[:,0]#diff差分pd.diff()#diagnostic白噪声检验, 返回stats和psm.stats.diagnostic.acorr_ljungbox(df, lags=1)#model#from statsmodels.tsa.arima_model import ARIMA #ARMAmodel = sm.tsa.ARIMA(df, order=(p,d,q))model = sm.tsa.ARMA()arma_res = model.fit(trend='nc', disp=-1)#BICmodel.bic#模型报告model.summary2()model.summary()model.tail()#拟合结果model.PRedict()#预测图fig, ax = plt.subplots(figsize=(10,8))fig = arma_res.plot_predict(start='1999m6', end='2001m5', ax=ax)legend = ax.legend(loc='upper left')#预测接下来5个数model.forecast(5)新闻热点
疑难解答