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

Bug: Box-cox transformation of model parameters when they can be negative #12

Closed
lukedyer-peak opened this issue Feb 3, 2020 · 4 comments

Comments

@lukedyer-peak
Copy link

It seems that sometimes the model parameters can be negative but we are trying to apply a box-cox transformation to them (c.f.

x0 = transformation.boxcox(
transformation.inv_boxcox(x0, self.box_cox_lambda),
boxcox
)
).

When I find what the min value that has been passed to the box-cox transformation it is min(y) = -21.....

The min value of my timeseries is 1 and has length 104.

The model is:
TBATS(seasonal_periods=[52], n_jobs=1, box_cox_bounds=(-2, 2))

See the following traceback:

Traceback (most recent call last):
....
  File "/home/{user}/python-dist/lib/python3.6/site-packages/tbats/abstract/Estimator.py", line 98, in fit
    best_model = self._do_fit(y)
  File "/home/{user}/python-dist/lib/python3.6/site-packages/tbats/tbats/TBATS.py", line 76, in _do_fit
    seasonal_model = self._choose_model_from_possible_component_settings(y, components_grid=components_grid)
  File "/home/{user}/python-dist/lib/python3.6/site-packages/tbats/abstract/Estimator.py", line 144, in _choose_model_from_possible_component_settings
    models = pool.map(self._case_fit, components_grid)
  File "/opt/conda/lib/python3.6/multiprocessing/pool.py", line 266, in map
    return self._map_async(func, iterable, mapstar, chunksize).get()
  File "/opt/conda/lib/python3.6/multiprocessing/pool.py", line 644, in get
    raise self._value
  File "/opt/conda/lib/python3.6/multiprocessing/pool.py", line 119, in worker
    result = (True, func(*args, **kwds))
  File "/opt/conda/lib/python3.6/multiprocessing/pool.py", line 44, in mapstar
    return list(map(*args))
  File "/home/{user}/python-dist/lib/python3.6/site-packages/tbats/abstract/Estimator.py", line 131, in _case_fit
    return case.fit(self._y)
  File "/home/{user}/python-dist/lib/python3.6/site-packages/tbats/abstract/Case.py", line 47, in fit
    best_model = self.fit_initial_model(y)
  File "/home/{user}/python-dist/lib/python3.6/site-packages/tbats/tbats/Case.py", line 22, in fit_initial_model
    return self.fit_case(y, self.components.without_arma())
  File "/home/{user}/python-dist/lib/python3.6/site-packages/tbats/abstract/Case.py", line 84, in fit_case
    return self.fit_with_starting_params(y, starting_params)
  File "/home/{user}/python-dist/lib/python3.6/site-packages/tbats/abstract/Case.py", line 102, in fit_with_starting_params
    return optimization.optimize(y, model_params).optimal_model()
  File "/home/{user}/python-dist/lib/python3.6/site-packages/tbats/abstract/ParamsOptimizer.py", line 105, in optimize
    'fatol': 1e-8,
  File "/home/{user}/python-dist/lib/python3.6/site-packages/scipy/optimize/_minimize.py", line 598, in minimize
    return _minimize_neldermead(fun, x0, args, callback, **options)
  File "/home/{user}/python-dist/lib/python3.6/site-packages/scipy/optimize/optimize.py", line 602, in _minimize_neldermead
    fxr = func(xr)
  File "/home/{user}/python-dist/lib/python3.6/site-packages/scipy/optimize/optimize.py", line 327, in function_wrapper
    return function(*(wrapper_args + args))
  File "/home/{user}/python-dist/lib/python3.6/site-packages/tbats/abstract/ParamsOptimizer.py", line 120, in _scale_and_calculate_likelihood
    return self._calculate_likelihood(optimization_vector)
  File "/home/{user}/python-dist/lib/python3.6/site-packages/tbats/abstract/ParamsOptimizer.py", line 126, in _calculate_likelihood
    params = self._starting_params.with_vector_values(optimization_vector)
  File "/home/{user}/python-dist/lib/python3.6/site-packages/tbats/abstract/ModelParams.py", line 215, in with_vector_values
    boxcox
  File "/home/{user}/python-dist/lib/python3.6/site-packages/tbats/transformation/BoxCox.py", line 22, in boxcox
    raise error.InputArgsException('y must have only positive values for box-cox transformation.')
tbats.error.InputArgsException.InputArgsException: y must have only positive values for box-cox transformation.

Package versions:

tbats==1.0.9
statsmodels==0.11.0
pmdarima==1.5.2

Let me know if you want to know anything else.

@lukedyer-peak lukedyer-peak changed the title Bug: Box-cox transformation of parameters when they can be negative Bug: Box-cox transformation of model parameters when they can be negative Feb 3, 2020
@cotterpl
Copy link
Collaborator

cotterpl commented Feb 6, 2020

I am writing just to notify you that I see the issue. It lies not in input data not being positive but starting state used for calculations (and being calculated inside TBATS) being negative. I am considering on how to approach it.

@popcornn1
Copy link

Hello, anything changed with this issue? I have the same problem

@cotterpl
Copy link
Collaborator

Unfortunately it is still not fixed.

@cotterpl
Copy link
Collaborator

I have just released a new version with a fix.

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

3 participants