4

I am getting an error while using SARIMA Model for Energy Consumption Project. Below is the code and error. If anyone have any solutions or suggestions, they would be greatly appreciated.

Code:

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)

Error:

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 Version = 3.7.6 Statsmodel = 1.2.0

Pranav Jaswal
  • 61
  • 1
  • 3

1 Answers1

-1

The problem should be your fit1 = model.fit(). You left the parentheses blank, so it doesn't apply. To apply it you have to use x_train and y_train. Therefore, try to write, inside the brackets, this: (x_train, y_train)

Here is the complete, but basic code, of what your solution should look like. Edit it to your liking with your preferences:

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)
Erling Olsen
  • 1
  • 4
  • 15
  • This syntax is not valid for Statsmodels, where the `fit` methods do not take X and y data as arguments. – cfulton Dec 22 '21 at 19:10