python statsmodel的使用
作者:朱小勇 时间:2021-04-22 13:38:13
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)
来源:https://www.cnblogs.com/judes/p/12620300.html
标签:python,statsmodel
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
java URL 获取PHP JSON 数据
2023-11-14 18:02:02
python机器学习pytorch 张量基础教程
2023-06-18 04:54:31
![](https://img.aspxhome.com/file/2023/4/65094_0s.png)
sp_delete_backuphistory
2008-06-07 13:59:00
ASP表单验证方法总结
2007-10-06 22:43:00
解决python DataFrame 打印结果不换行问题
2023-11-20 23:12:25
![](https://img.aspxhome.com/file/2023/4/84084_0s.jpg)
Python格式化输出字符串的五种方法总结
2023-03-30 02:07:42
![](https://img.aspxhome.com/file/2023/4/86344_0s.jpg)
http状态码一览表以及HTTP响应的返回头信息
2010-03-31 14:45:00
python中强制关闭线程与协程与进程方法
2023-05-11 10:24:48
![](https://img.aspxhome.com/file/2023/4/65074_0s.png)
用sqlalchemy构建Django连接池的实例
2021-09-22 20:20:30
Python tkinter 树形列表控件(Treeview)的使用方法
2023-10-06 23:14:47
![](https://img.aspxhome.com/file/2023/2/62562_0s.png)
牛刀小试YUI compressor(YUI安装方法)
2009-02-12 16:18:00
![](https://img.aspxhome.com/file/UploadPic/20092/12/yuiyasuo-71s.png)
网页广告 Banner 设计图文手册
2007-10-18 19:56:00
![](https://img.aspxhome.com/file/UploadPic/up/2007101820293575.jpg)
Python多进程机制实例详解
2021-04-10 00:16:44
英文版面设计的8个禁忌
2009-10-14 20:42:00
![](https://img.aspxhome.com/file/UploadPic/200910/14/01-84s.jpg)
Python决策树和随机森林算法实例详解
2021-12-15 21:44:24
![](https://img.aspxhome.com/file/2023/9/77919_0s.png)
在Mac上删除自己安装的Python方法
2021-03-22 22:10:57
python判断变量是否为int、字符串、列表、元组、字典的方法详解
2022-09-28 05:11:57
最新PyCharm从安装到PyCharm永久激活再到PyCharm官方中文汉化详细教程
2022-09-24 01:38:47
![](https://img.aspxhome.com/file/2023/0/82940_0s.png)
asp中通过addnew添加内容后取得当前文章的自递增ID的方法
2011-02-05 11:05:00
如何使用图片精灵优化你的网站
2009-07-21 11:35:00
![](https://img.aspxhome.com/file/UploadPic/20097/21/how_to_image_sprites-95s.jpg)