Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LinAlgError: Incompatible dimensions #86

Open
VedAustin opened this issue Jul 15, 2021 · 3 comments
Open

LinAlgError: Incompatible dimensions #86

VedAustin opened this issue Jul 15, 2021 · 3 comments
Assignees

Comments

@VedAustin
Copy link

from kats.models.theta import ThetaModel, ThetaParams
params = ThetaParams(m=7) # Weekly seasonality 
m = ThetaModel(data_ts, params) # data_ts -> daily data points
m.fit()

gives this error:

Optimization failed to converge. Check mle_retvals.

---------------------------------------------------------------------------
LinAlgError                               Traceback (most recent call last)
/var/folders/25/t45ty5ps70l5y9gww_k11zy40000gq/T/ipykernel_44596/687703454.py in <module>
----> 1 m.fit()

~/kats/lib/python3.9/site-packages/kats/models/theta.py in fit(self, **kwargs)
    119         # creating x and intercept variables to fit a straight line
    120         regr = np.vstack([np.arange(self.n), np.ones(self.n)]).T
--> 121         slope, _ = np.linalg.lstsq(regr, deseas_data.value.values)[0]
    122         # pyre-fixme[16]: `ThetaModel` has no attribute `drift`.
    123         self.drift = slope / 2

<__array_function__ internals> in lstsq(*args, **kwargs)

~/kats/lib/python3.9/site-packages/numpy/linalg/linalg.py in lstsq(a, b, rcond)
   2273     m2, n_rhs = b.shape[-2:]
   2274     if m != m2:
-> 2275         raise LinAlgError('Incompatible dimensions')
   2276 
   2277     t, result_t = _commonType(a, b)

LinAlgError: Incompatible dimensions

Ran the same data under Prophet model and it fits and forecasts w/o errors. Any pointers as to the source of the problem?

@iamxiaodong
Copy link
Contributor

looks like the convergence is failed, do you mind sharing your time series data here so that we can take a look at? thanks.

@VedAustin
Copy link
Author

sure .. here you go:
data_gh.csv

@VedAustin
Copy link
Author

model_params = EnsembleParams(
[
#     BaseModelParams("arima", arima.ARIMAParams(p=1, d=1, q=1)),
#     BaseModelParams("sarima", sarima.SARIMAParams(p=2, d=1, q=1,trend='ct',seasonal_order=(1, 0, 1, 12), enforce_invertibility=False, enforce_stationarity=False)),
    BaseModelParams('prophet', prophet.ProphetParams()),
    BaseModelParams('linear', linear_model.LinearModelParams()),
    BaseModelParams('quadratic', quadratic_model.QuadraticModelParams()),
    BaseModelParams('theta', theta.ThetaParams(m=7))
])

KatsEnsembleParam = {
    'models': model_params,
    'aggregation': 'median',
    'seasonality_length': 7,
    'decomposition_method': 'multiplicative'
}

Errors out at 'arima', 'sarima', 'linear' and 'quadratic' but funnily enough not at 'theta'.
Example of error message for 'linear':
ValueError: endog and exog matrices are different sizes

Data set same as above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants