Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to make forecasts strictly positive?

See original GitHub issue
  • scikit-hts version: 0.5.5
  • Python version: 3.6
  • Operating System: Windows


Want to make my predictions to be strictly positive. For that, I want to make use of the log transformation function and I’ve passed a custom transformation function to the transform parameter. The final results still have negative forecasts. I want to know if I’m passing the custom function correctly. If yes, want to know why the results are negative?.

I’ve created the custom function in 2 ways. Here goes the first one.

from collections import namedtuple
transform = namedtuple('transform', {'func': 'Callable', 'inv_func': 'Callable'})
transformer = transform(np.log1p, np.exp)
htsmodel = hts.HTSRegressor(model = 'auto_arima', revision_method = 'BU', n_jobs = 0, transform = transformer)

And the second one

transformer = hts._t.Transform(np.log1p, np.exp)
htsmodel = hts.HTSRegressor(model = 'auto_arima', revision_method = 'BU', n_jobs = 0, transform = transformer)

Unfortunately, None of them have any effect in bringing out the positive forecasts. So, Am I passing them the wrong way? or It’s something else.

PS: When I’m transforming them explicitly before fitting and back-transforming them after predictions. The forecasts are positive.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

carlomazzaferrocommented, Jun 5, 2021

@aakashparsi good catch, not sure how this passed the tests but the culprit is this:

>>> from collections import namedtuple
>>> Employee = namedtuple('Employee', ['name', 'id'])
>>> employee = Employee('Guido', 1)
>>> employee
Employee(name='Guido', id=1)
>>> from typing import NamedTuple
>>> isinstance(employee, NamedTuple)
False  # I assumed this was True

Need to make an adjustment to the code, will lyk when it is in.

carlomazzaferrocommented, Jun 5, 2021
Read more comments on GitHub >

github_iconTop Results From Across the Web

time series - How to achieve strictly positive forecasts?
5. One of the easiest, but not always correct thing to do in such case is simply forecast the log of the variable....
Read more >
generate strictly positive values using arima.sim in R
This command give me both positive and negative values. r · forecasting · Share.
Read more >
12.3 Ensuring forecasts stay within limits - OTexts
Positive forecasts. To impose a positivity constraint, simply work on the log scale, by specifying the Box-Cox parameter ...
Read more >
Exponential smoothing and non-negative data
If the observational sample space is not restricted to be strictly positive, the. Class X models can have an infinite forecast variances ...
Read more >
M5 Forecasting - Accuracy | Kaggle
The box cox method will ensure positive predictions but the input must be non negative and greater than 0. As for the nature...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found