如何使用pmdarima或其他方法反演二次差分?

2024-04-25 04:34:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我在statsmodels中运行一个VARMA模型,我的一些输入需要差分两次才能保持平稳。VARMA模型没有差分参数,所以我需要在运行模型之前进行差分,然后在自己之后进行反差分

我尝试过使用pmdarima diff_inv,但我花了一段时间使用它,无法让它返回原始数组进行二次差分反演。我认为这个问题是用席参数,所以如果有人能告诉我如何使用PMDARIMA来反二次差,也可以工作。p>

现在,我正试图找出如何在没有pmdarima帮助的情况下反演二次差分

使用这段代码,我成功地将一个数组差分两次,然后将差分求逆得到原始数组

y = pd.Series([5, 3, 6, 2, 10]) #original data
diff1 = y.diff() #get first difference

[NaN, -2, 3, -4, 8] #(returns this but in pd series form)

diff2 = y.diff().diff() #get second difference

[NaN, NaN, 5, -7, 12]

#now inverse the differencing
inv1 = diff2.cumsum()-2 #undo one level of differencing. subtract xi,2=-2 since that's the first value of the original data differenced once
inv1[1]=-2 #add -2 as the second value in the series

[NaN, -2, 3, -4, 8] #we get the same series as after 1 level of differencing applied to the original

 inv2 = inv1.cumsum()+5 #undo another level of differencing.  add xi,1=5 since that's the first value of the original series
 inv2[0]=5 #add 5 as the first value of the series

[5, 3, 6, 2, 10] #we get the original data

现在,我只需要知道如何确定我的应用程序的席,1和席,2个值(在这个例子中是5和2)。由于我将第二个不同的输入数据,应用模型,然后反演差分,我认为我可以从输入数据的第一个值得到席,1,但是我如何确定席,2?p>


Tags: ofthe模型datagetvaluediff差分