解决FutureWarning: The default method ‘yw‘ can produce PACF values outside of the [-1,1] interval.

出现了FutureWarning: The default method 'yw' can produce PACF values outside of the [-1,1] interval. After 0.13, the default will change tounadjusted Yule-Walker ('ywm'). You can use this method now by setting method='ywm'.

warnings.warn(

首先进行翻译:

FutureWarning:默认方法“yw”可能会产生[-1,1]区间之外的PACF值。0.13之后,默认值将更改为tounadjusted Yule Walker(“ywm”)。现在可以通过设置method='ywm'来使用此方法

方法一:设置method='ywm'

找到与PACF值有关的函数

fig = sm.graphics.tsa.plot_pacf(train, lags=20, ax=ax2)

修改后

fig = sm.graphics.tsa.plot_pacf(train, lags=20, ax=ax2,method='ywm')

此时运行不会出现警告

方法二:将statsmodels.api改成0.13之前的版本

未操作 但有利有弊 两版本的不同可能解决这个问题,但导致其他函数出现错误或警告

import numpy as np import matplotlib.pyplot as plt import pandas as pd import statsmodels.tsa.api as smt import statsmodels.tsa.arima.model as smt2 from statsmodels.stats.diagnostic import acorr_ljungbox as lb_test from statsmodels.graphics.tsaplots import plot_pacf 某城市過去63年中每年降雪量 y def drawts(y,pname): ##draw ax plot_pacf(y, method='ywm') fig = plt.figure(figsize=(10,8)) ts_ax=plt.subplot2grid((2,2),(0,0),colspan=2) acf_ax=plt.subplot2grid((2,2),(1,0)) pacf_ax=plt.subplot2grid((2,2),(1,1)) ##draw plot ts_ax.plot(y,'*-') ts_ax.set_title('Time Series Analysis Plots') smt.graphics.plot_acf(y,lags=None,ax=acf_ax,alpha=0.05) ##2sigma smt.graphics.plot_pacf(y,lags=None,ax=pacf_ax,alpha=0.05) ##2sigma #plt.savefig('%s.jpg'%pname,dpi=256) plt.show() plt.close() def purerandtest(y): a,b=lb_test(y,lags=None,boxpierce=False) LB_purerand=pd.DataFrame(np.c_[a,b],columns=['LB','Pvalue']) LB_purerand['lags']=range(1,len(a)+1) print('----time series: LB pure randomness test----') print(LB_purerand) data = 'table3.20' y = pd.read_csv('%s.csv'%data , header=None) y.iloc[:,0] = y.iloc[:,0].astype('float') y = y.values[:,0] y = y[1:]-y[:-1] drawts(y,data) purerandtest(y) C:\ProgramData\Anaconda3\lib\site-packages\statsmodels\graphics\tsaplots.py:348: FutureWarning: The default method 'yw' can produce PACF values outside of the [-1,1] interval. After 0.13, the default will change tounadjusted Yule-Walker ('ywm'). You can use this method now by setting method='ywm'. warnings.warn( --------------------------------------------------------------------------- ValueError Traceback (most recent call last) C:\ProgramData\Anaconda3\lib\site-packages\numpy\lib\index_tricks.py in __getitem__(self, key) 382 try: --> 383 axis = int(item) 384 continue ValueError: invalid literal for int() with base 10: 'lb_stat' The above exception was the direct cause of the following exception: ValueError Traceback (most recent call last) ~\AppData\Local\Temp\ipykernel_29104\1169988139.py in <module> 5 y = y[1:]-y[:-1] 6 drawts(y,data) ----> 7 purerandtest(y) ~\AppData\Local\Temp\ipykernel_29104\1354843218.py in purerandtest(y) 1 def purerandtest(y): 2 a,b=lb_test(y,lags=None,boxpierce=False) ----> 3 LB_purerand=pd.DataFrame(np.c_[a,b],columns=['LB','Pvalue']) 4 LB_purerand['lags']=range(1,len(a)+1) 5 print('----time series: LB pure randomness test----') C:\ProgramData\Anaconda3\lib\site-packages\numpy\lib\index_tricks.py in __getitem__(self, key) 384 continue 385 except (ValueError, TypeError) as e: --> 386 raise ValueError("unknown special directive") from e 387 elif type(item) in ScalarType: 388 newobj = array(item, ndmin=ndmin) ValueError: unknown special directive
最新发布
10-21
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值