当前位置:   article > 正文

Python进行ARMA模型建模_arma模型python代码

arma模型python代码
  1. import pandas as pd
  2. import matplotlib.pyplot as plt
  3. import seaborn as sns
  4. import statsmodels.api as sm
  5. from statsmodels.tsa.arima.model import ARIMA
  6. sns.set_theme()# 设置风格
  7. %config InlineBackend.figure_format = 'retina' # 让图片更清晰
  8. df = pd.read_excel('D:/data/HOUSTNSA.xlsx')# 导入数据
  9. print(df)
  10. data = df['HOUSTNSA'].values
  11. year = pd.date_range("1/1/1959", periods=770, freq="M")
  12. ts = pd.DataFrame(data, index=year,columns=['HOUSTNSA'])
  13. print(ts)
  14. res = sm.tsa.arma_order_select_ic(
  15. ts,
  16. max_ar=2,
  17. max_ma=2,ic=["aic", "bic"]
  18. )# 定阶
  19. 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)}

  1. mod = ARIMA(ts,order=(2, 0, 2))
  2. res = mod.fit()
  3. print(res.summary())# 拟合模型
  1. fig = plt.figure(figsize=(16, 9))
  2. fig = res.plot_diagnostics(fig=fig, lags=30)
  3. plt.savefig("tsplot2.png", dpi = 600, bbox_inches = 'tight')
  4. plt.show()

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/91859?site
推荐阅读
相关标签
  

闽ICP备14008679号