3

使用 SARIMA 模型进行能源消耗项目时出现错误。下面是代码和错误。如果有人有任何解决方案或建议,他们将不胜感激。

代码:

from statsmodels.tsa.statespace import sarimax
from statsmodels.graphics.tsaplots import plot_acf, plot_pacf

data = pd.read_csv("C:\\Users\\Jaswal\\Desktop\\Analytics Vidhya\\Assignments\\energy consumption.csv", index_col=None)
data

DATE    ENERGY_INDEX
0   01/1939 3.3842
1   02/1939 3.4100
2   03/1939 3.4875
3   04/1939 3.5133
4   05/1939 3.5133
... ... ...
964 05/2019 91.9046
965 06/2019 98.4397
966 07/2019 112.9469
967 08/2019 111.6645
968 09/2019 102.2911

model = sarimax.SARIMAX(data['ENERGY_INDEX'], seasonal_order=(1,1,1,7), order=(2,1,2))
fit1 = model.fit()

valid_data['SARIMA'] = fit1.predict(start="01/1939", end="09/2019", dynamic=True)

错误:

LinAlgError                               Traceback (most recent call last)
<ipython-input-55-0d31300a6c27> in <module>
      1 # fit model
      2 model = sarimax.SARIMAX(data['ENERGY_INDEX'], seasonal_order=(1,1,1,7), order=(2,1,2))
----> 3 fit1 = model.fit()
      4 
      5 # make predictions

~\Anaconda3\lib\site-packages\statsmodels\tsa\statespace\representation.py in _initialize_state(self, prefix, complex_step)
    982                 raise RuntimeError('Initialization is incomplete.')
    983             self._statespaces[prefix].initialize(self.initialization,
--> 984                                                  complex_step=complex_step)
    985         else:
    986             raise RuntimeError('Statespace model not initialized.')

statsmodels\tsa\statespace\_representation.pyx in statsmodels.tsa.statespace._representation.dStatespace.initialize()

statsmodels\tsa\statespace\_representation.pyx in statsmodels.tsa.statespace._representation.dStatespace.initialize()

statsmodels\tsa\statespace\_initialization.pyx in statsmodels.tsa.statespace._initialization.dInitialization.initialize()

statsmodels\tsa\statespace\_initialization.pyx in statsmodels.tsa.statespace._initialization.dInitialization.initialize_stationary_stationary_cov()

statsmodels\tsa\statespace\_tools.pyx in statsmodels.tsa.statespace._tools._dsolve_discrete_lyapunov()

LinAlgError: Schur decomposition solver error.

Python 版本 = 3.7.6 统计模型 = 1.2.0

4

1 回答 1

0

问题应该是你的fit1 = model.fit(). 您将括号留空,因此不适用。要应用它,您必须使用x_trainand y_train。因此,请尝试在括号内写出:(x_train, y_train)

这是您的解决方案应该是什么样子的完整但基本的代码。根据您的喜好编辑它:

from statsmodels.tsa.statespace import sarimax
from statsmodels.graphics.tsaplots import plot_acf, plot_pacf

data = pd.read_csv("C:\\Users\\Jaswal\\Desktop\\Analytics Vidhya\\Assignments\\energy consumption.csv", index_col=None)
data

DATE    ENERGY_INDEX
0   01/1939 3.3842
1   02/1939 3.4100
2   03/1939 3.4875
3   04/1939 3.5133
4   05/1939 3.5133
... ... ...
964 05/2019 91.9046
965 06/2019 98.4397
966 07/2019 112.9469
967 08/2019 111.6645
968 09/2019 102.2911

model = sarimax.SARIMAX(data['ENERGY_INDEX'], seasonal_order=(1,1,1,7), order=(2,1,2))
fit1 = model.fit(x_train,y_train) #update

valid_data['SARIMA'] = fit1.predict(start="01/1939", end="09/2019", dynamic=True)
于 2021-12-22T18:25:38.627 回答