LinAlgError: SVD did not converge error when fitted with SARIMAX model
When I fitted the SARIMAX model with 10 data points, it failed to converge when the model tried to fit. I found this when I tried to look at the summary.
import numpy as np
import pandas as pd
from statsmodels.tsa.statespace.sarimax import SARIMAX
import random
y = []
# Set a length of the list to 10
for i in range(0, 10):
x = round(random.uniform(50, 500), 2)
y.append(x)
model = SARIMAX(y, order=(0,2,2), seasonal_order=(0,0,0,0))
fitted_model = model.fit()
forecast_results = fitted_model.forecast(12)
ConvergenceWarning: Maximum Likelihood optimization failed to converge. Check mle_retvals warnings.warn("Maximum Likelihood optimization failed to "
If the issue has not been resolved, please file it in the issue tracker.
Expected Output
A clear and concise description of what you expected to happen.
Output of import statsmodels.api as sm; sm.show_versions()
[paste the output of import statsmodels.api as sm; sm.show_versions() here below this line]
0.13.2
Thanks for reporting, but I can't replicate this error. Can you post the full exception message including the stack trace?
Sure. See below:
/Users/***/opt/anaconda3/lib/python3.8/site-packages/statsmodels/tsa/statespace/sarimax.py:902: RuntimeWarning: Mean of empty slice. params_variance = (residuals[k_params_ma:] ** 2).mean() /Users/***/opt/anaconda3/lib/python3.8/site-packages/numpy/core/_methods.py:189: RuntimeWarning: invalid value encountered in double_scalars ret = ret.dtype.type(ret / rcount) /Users/***/opt/anaconda3/lib/python3.8/site-packages/statsmodels/tsa/statespace/sarimax.py:978: UserWarning: Non-invertible starting MA parameters found. Using zeros as starting parameters. warn('Non-invertible starting MA parameters found.' /Users/***/opt/anaconda3/lib/python3.8/site-packages/statsmodels/base/model.py:604: ConvergenceWarning: Maximum Likelihood optimization failed to converge. Check mle_retvals warnings.warn("Maximum Likelihood optimization failed to "
@ChadFulton
Here is the y vector input used in the model. Does this help?
import numpy as np
import pandas as pd
from statsmodels.tsa.statespace.sarimax import SARIMAX
import random
y = []
# Set a length of the list to 10
for i in range(0, 10):
x = round(random.uniform(50, 500), 2)
y.append(x)
# y = [454.85, 367.44, 411.17, 428.79, 302.61, 164.83, 165.9, 412.9, 413.64, 431.65]
model = SARIMAX(y, order=(0,2,2), seasonal_order=(0,0,0,0))
fitted_model = model.fit()
# forecast_results = [nan nan nan nan nan nan nan nan nan nan nan nan]
forecast_results = fitted_model.forecast(12)
This appears to be fixed in the current (unreleased) main branch, since when I run the above code, using the y = [454.85, 367.44, 411.17, 428.79, 302.61, 164.83, 165.9, 412.9, 413.64, 431.65] that you have commented out, I get:
> print(forecast_results)
[447.08657294 443.74877594 440.41097895 437.07318195 433.73538496
430.39758796 427.05979097 423.72199397 420.38419698 417.04639998
413.70860299 410.37080599]
Which version is the unreleased one that you tested on? @ChadFulton