python statsmodel的使用

2020-12-22 0 166

1、Pandas

Python Data Analysis Library 或 pandas 是基于NumPy 的一种工具,相当于这是Python官方自己的一套库

statsmodel是基于Pandas开发的一套库,用于一些描述统计、统计模型估计、推断、预测

2、自回归模型(AutoRegression model,AR)

自回归,从物理的角度来理解就是:当前记录与其历史记录的差值。eg,自回归认为历史的发展是一条斜率一定的直线。

3、滑动平均模型(moving average model, MA)

移动平均,从物理的角度来理解就是:当前记录是历史记录的均值。eg,移动平均模型认为历史的发展是一条水平的线。

4、高级时间序列模型ARMA

ARMA就是把AR和MA结合在一起的一种算法,当AR和MA混合在一起,可以认为是一个y=ax+b的过程,自回归提供了a这个系数,移动平均提供了b这个截距。

5、高级时间序列模型ARIMA【autoregression intergrated moving average差分自回归移动平均】

ARIMA中,I指代的差分,其实是 前后时间上数值的差异,ARIMA就是使用差分的数据来进行ARMA建模

6、ARMA测试

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import statsmodels.api as sm
from statsmodels.graphics.tsaplots import acf, pacf, plot_acf, plot_pacf
from statsmodels.tsa.arima_model import ARMA
from statsmodels.tsa.stattools import arma_order_select_ic

if __name__ == \"__main__\":

  time_series = pd.Series(
    [151.0, 188.46, 199.38, 219.75, 241.55, 262.58, 328.22, 396.26, 442.04, 517.77, 626.52, 717.08, 824.38, 913.38,
     1088.39, 1325.83, 1700.92, 2109.38, 2499.77, 2856.47, 3114.02, 3229.29, 3545.39, 3880.53, 4212.82, 4757.45,
     5633.24, 6590.19, 7617.47, 9333.4, 11328.92, 12961.1, 15967.61])
  # print(\'BIC求解的模型阶次为\', arma_order_select_ic(time_series, max_ar=10, max_ma=6, ic=\'bic\')[\'bic_min_order\'])
  print(\'time_series:\', len(time_series))
  my_arma = ARMA(time_series, (1, 0)) # 这里的(1, 0)从arma_order_select_ic函数返回,但是这里返回6,7运行失败
  model = my_arma.fit()
  result = model.forecast(10)[0]
  print(\'result:\', result)

python statsmodel的使用

以上就是python statsmodel的使用的详细内容,更多关于python statsmodel的资料请关注自学编程网其它相关文章!

遇见资源网 Python python statsmodel的使用 http://www.ox520.com/27707.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务