赞
踩
- import pandas as pd
- import matplotlib.pyplot as plt
- import seaborn as sns
- import statsmodels.api as sm
- from statsmodels.tsa.arima.model import ARIMA
-
- sns.set_theme()# 设置风格
- %config InlineBackend.figure_format = 'retina' # 让图片更清晰
-
- df = pd.read_excel('D:/data/HOUSTNSA.xlsx')# 导入数据
- print(df)
-
- data = df['HOUSTNSA'].values
- year = pd.date_range("1/1/1959", periods=770, freq="M")
- ts = pd.DataFrame(data, index=year,columns=['HOUSTNSA'])
-
- print(ts)
-
- res = sm.tsa.arma_order_select_ic(
- ts,
- max_ar=2,
- max_ma=2,ic=["aic", "bic"]
- )# 定阶
- res
{'aic': 0 1 2
0 7778.111863 7089.007586 6790.807042
1 6500.479592 6470.421294 6442.842546
2 6461.160567 6460.092841 6441.241159,
'bic': 0 1 2
0 7787.404644 7102.946758 6809.392604
1 6514.418764 6489.006857 6466.074499
2 6479.746129 6483.324793 6469.119502,
'aic_min_order': (2, 2),
'bic_min_order': (1, 2)}
- mod = ARIMA(ts,order=(2, 0, 2))
- res = mod.fit()
- print(res.summary())# 拟合模型
- fig = plt.figure(figsize=(16, 9))
- fig = res.plot_diagnostics(fig=fig, lags=30)
- plt.savefig("tsplot2.png", dpi = 600, bbox_inches = 'tight')
- plt.show()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。