在statsmodel中使用sarima时,如何解决force_stationarity错误后如何解决“将NaN浮动为整数”问题

时间:2019-05-04 12:19:58

标签: python time-series statsmodels forecasting arima

我试图在时间序列上拟合sarima模型,但遇到“ ValueError:在forced_stationarity设置为True的情况下发现非平稳起始自回归参数”错误。

如这里的推荐:R Arima works but Python statsmodels SARIMAX throws invertibility error和我曾经使用过的https://github.com/statsmodels/statsmodels/pull/3506

start_params = [0,0,0,0,1]

model = sm.tsa.statespace.SARIMAX(data,order=(5, 1, 1), seasonal_order = (1,0,0,12),enforce_stationarity = True, enforce_invertibility = True)  
results = model.fit(start_params= [0, 0, 0, 0, 1]) 
print(results.summary())

但这会导致错误:

C:\Users\windisch\AppData\Local\Continuum\anaconda3\lib\site-packages\statsmodels\tsa\base\tsa_model.py:171: ValueWarning: No frequency information was provided, so inferred frequency MS will be used.

% freq, ValueWarning)

 C:\Users\windisch\AppData\Local\Continuum\anaconda3\lib\site-packages\statsmodels\tsa\statespace\tools.py:600: RuntimeWarning: invalid value encountered in long_scalars

  y[k-1, i] = (y[k, i] - y[k, k]*y[k, k-i-1]) / (1 - y[k, k]**2)

---------------------------------------------------------------------------

ValueError                                Traceback (most recent call last)

<ipython-input-671-69af3fea1d4b> in <module>()

  9                                    seasonal_order =   (1,0,0,12),enforce_stationarity = True, enforce_invertibility = True)

 10

---> 11 results = model.fit(start_params= [0, 0, 0, 0, 1]) #start_params=[0, 0, 0, 1] start_params= [0, 0, 0, 0, 1]

 12 print(results.summary())

 13



~\AppData\Local\Continuum\anaconda3\lib\site-packages\statsmodels\tsa\statespace\mlemodel.py in fit(self, start_params, transformed, cov_type, cov_kwds, method, maxiter, full_output, disp, callback, return_params, optim_score, optim_complex_step, optim_hessian, flags, **kwargs)

449         # Unconstrain the starting parameters

450         if transformed:

--> 451             start_params = self.untransform_params(np.array(start_params))

452

 453         # Maximum likelihood estimation


~\AppData\Local\Continuum\anaconda3\lib\site-packages\statsmodels\tsa\statespace\sarimax.py in untransform_params(self, constrained)

1430             if self.enforce_stationarity:

1431                 unconstrained[start:end] = (

 -> 1432                     unconstrain_stationary_univariate(constrained[start:end])

1433                 )

1434             else:



~\AppData\Local\Continuum\anaconda3\lib\site-packages\statsmodels\tsa\statespace\tools.py in unconstrain_stationary_univariate(constrained)

598     for k in range(n-1, 0, -1):

599         for i in range(k):

--> 600             y[k-1, i] = (y[k, i] - y[k, k]*y[k, k-i-1]) / (1 - y[k, k]**2)

601     r = y.diagonal()

602     x = r / ((1 - r**2)**0.5)



ValueError: cannot convert float NaN to integer

数据的前10行如下:

  Auftragsdatum
  2010-02-01    -467.0
  2010-03-01    1180.0
  2010-04-01    -434.0
  2010-05-01     279.0
  2010-06-01    -249.0
  2010-07-01    -247.0
  2010-08-01    -775.0
  2010-09-01    1772.0
  2010-10-01     522.0
  2010-11-01    -642.0
  Name: Anzahl, dtype: float64

该如何解决?

0 个答案:

没有答案