arima

[python] 时间序列分析之ARIMA

自作多情 提交于 2019-12-05 22:13:19
1 时间序列与时间序列分析 在生产和科学研究中,对某一个或者一组变量 进行观察测量,将在一系列时刻 所得到的离散数字组成的序列集合,称之为时间序列。 时间序列分析是根据系统观察得到的时间序列数据,通过曲线拟合和参数估计来建立数学模型的理论和方法。时间序列分析常用于国民宏观经济控制、市场潜力预测、气象预测、农作物害虫灾害预报等各个方面。 2 时间序列建模基本步骤 获取被观测系统时间序列数据; 对数据绘图,观测是否为平稳时间序列;对于非平稳时间序列要先进行d阶差分运算,化为平稳时间序列; 经过第二步处理,已经得到平稳时间序列。要对平稳时间序列分别求得其自相关系数ACF 和偏自相关系数PACF ,通过对自相关图和偏自相关图的分析,得到最佳的阶层 p 和阶数 q 由以上得到的 ,得到ARIMA模型。然后开始对得到的模型进行模型检验。 3 ARIMA实战解剖 原理大概清楚,实践却还是会有诸多问题。相比较R语言,Python在做时间序列分析的资料相对少很多。下面就通过Python语言详细解析后三个步骤的实现过程。 文中使用到这些基础库: 。 对其调用如下 from __future__ import print_function import pandas as pd import numpy as np from scipy import stats import matplotlib

ARIMA模型--粒子群优化算法(PSO)和遗传算法(GA)

一世执手 提交于 2019-12-05 04:07:46
ARIMA 模型 ARIMA模型(英语:AutoregressiveIntegratedMovingAverage model), 差分整合移动平均自回归模型 ,又称 整合移动平均自回归模型 (移动也可称作滑动), 时间序列 预测分析方法之一。ARIMA(p,d,q)中,AR是"自回归",p为自回归项数;MA为"滑动平均",q为滑动平均项数,d为使之成为平稳序列所做的差分次数(阶数)。 ARIMA(p,d,q)模型是 ARMA (p,q)模型的扩展。ARIMA(p,d,q)模型可以表示为: 其中 L 是滞后算子(Lag operator), 1. 平稳性: 平稳性就是要求经由样本时间序列所得到的拟合曲线,在未来的一段时间内仍能顺着现有状态“惯性”地延续下去; 平稳性要求序列的均值和方差不发生明显变化; 方差越大,数据波动越大,方差计算公式如下式所示: 方差等于1,那么标准差也就是1,表示概率函数在对称轴左右偏差1的位置导数为0,即为拐点。期望为0,表示概率函数以y轴为对称轴。 平稳性分为严平稳和弱平稳 严平稳:严平稳表示的分布不随时间的改变而改变,如:白噪声(正态),无论怎么取,都是期望为0,方差为1; 弱平稳:期望与相关系数(依赖性)不变,未来某时刻的t值Xt就要依赖于它的过去信息,所以需要依赖性; 2. 差分法:时间序列在 t 与 t-1 时刻的差值 3. 自回归模型( AR

compatibility issue of magrittr and arima in R

你离开我真会死。 提交于 2019-12-04 09:31:10
consider the following example: library(tidyverse) set.seed(1) forecast::forecast x <- cumsum(rnorm(10)) y1 <- arima(x, order = c(1, 0, 0)) y2 <- x %>% arima(order = c(1, 0, 0)) length(fitted(y1)) [1] 10 length(fitted(y2)) [1] 0 The objects y1 and y2 are almost identical, the only exceptions being the slots call and series . So I guess that is where the fitted functions starts its magic. I would really like to work with y1 instead of y2 . Does anyone know an alternative function to fitted which produces the same result? EDIT2: The above "bug" does not appear if the forecast package is not

non Invertible of a ARIMA model

匿名 (未验证) 提交于 2019-12-03 08:41:19
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to write a code to generate a series of arima model and compare different models.The code is as follow. p=0 q=0 d=0 pdq=[] aic=[] for p in range(6): for d in range(2): for q in range(4): arima_mod=sm.tsa.ARIMA(df,(p,d,q)).fit(transparams=True) x=arima_mod.aic x1= p,d,q print (x1,x) aic.append(x) pdq.append(x1) keys = pdq values = aic d = dict(zip(keys, values)) print (d) minaic=min(d, key=d.get) for i in range(3): p=minaic[0] d=minaic[1] q=minaic[2] print (p,d,q) Where 'df' is the time series data.And the output is as follow, (0,

Python Statsmodel ARIMA start [stationarity]

匿名 (未验证) 提交于 2019-12-03 03:06:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I just began working on time series analysis using statsmodels. I have a dataset with dates and values (for about 3 months). I am facing some issues with providing the right order to the ARIMA model. I am looking to adjust for trends and seasonality and then compute outliers. My 'values' are not stationary and statsmodel says that I have to either induce stationarity or provide some differencing to make it work. I played around with different ordering (without understanding deeply about the consequences of changing p,q and d). When I

Python ARIMA exogenous variable out of sample

匿名 (未验证) 提交于 2019-12-03 03:05:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to predict a time series in python statsmodels ARIMA package with the inclusion of an exogenous variable, but cannot figure out the correct way to insert the exogenous variable in the predict step. See here for docs. import numpy as np from scipy import stats import pandas as pd import statsmodels.api as sm vals = np.random.rand(13) ts = pd.TimeSeries(vals) df = pd.DataFrame(ts, columns=["test"]) df.index = pd.Index(pd.date_range("2011/01/01", periods = len(vals), freq = 'Q')) fit1 = sm.tsa.ARIMA(df, (1,0,0)).fit() #this works

auto.arima() equivalent for python

匿名 (未验证) 提交于 2019-12-03 02:47:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I am trying to predict weekly sales using ARMA ARIMA models. I could not find a function for tuning the order(p,d,q) in statsmodels . Currently R has a function auto.arima() which will tune the (p,d,q) parameters. How do I go about choosing the right order for my model? Are there any libraries available in python for this purpose? 回答1: You can implement a number of approaches: ARIMAResults include aic and bic . By their definition, (see here and here ), these criteria penalize for the number of parameters in the model. So you may

auto.arima() equivalent for python

匿名 (未验证) 提交于 2019-12-03 02:08:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to predict weekly sales using ARMA ARIMA models. I could not find a function for tuning the order(p,d,q) in statsmodels . Currently R has a function auto.arima() which will tune the (p,d,q) parameters. How do I go about choosing the right order for my model? Are there any libraries available in python for this purpose? 回答1: You can implement a number of approaches: ARIMAResults include aic and bic . By their definition, (see here and here ), these criteria penalize for the number of parameters in the model. So you may use these

JRI and ARIMA integration

匿名 (未验证) 提交于 2019-12-03 01:48:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have one last question, but I really need help on this one. The very last thing for my project is that I have to make ARIMA, to work under JRI. All everything is working, but one little piece of code is not working properly. Here's the code: re.eval("library(forecast);"); re.assign("y", arrayStr); re.eval("datats<-y;"); re.eval("arima<-auto.arima(datats);"); re.eval("fcast<-forecast(arima);"); REXP fs = re.eval("summary(fcast);"); double[] forecast = fs.asDoubleArray(); for(int i=0; i<forecast.length; i++) System.out.println(forecast[i]);

Python ARIMA model, predicted values are shifted

匿名 (未验证) 提交于 2019-12-03 01:06:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am new to Python ARIMA implementation. I have a data at 15 min frequency for few months. In my attempt to follow the Box-Jenkins method to fit a timeseries model. I ran into an issue towards the end. The ACF-PACF graph for the time series (ts) and the difference series (ts_diff) are given. I used ARIMA (5,1,2) and finally I plotted the fitted values(green) and original values(blue). As you can from figure , there is a clear shift(by one) in values. What am I doing wrong? Is the prediction bad? Any insight will be helpful. 回答1: This is a