antoinecarme / pyaf

PyAF is an Open Source Python library for Automatic Time Series Forecasting built on top of popular pydata modules.
BSD 3-Clause "New" or "Revised" License
459 stars 72 forks source link

Disallow negative predictions? #69

Closed mgiangreco closed 6 years ago

mgiangreco commented 7 years ago

Is there a way to tell the engine that predictions cannot be negative? Obviously it is possible to change negative predictions to zero after the fact...

antoinecarme commented 7 years ago

No, we cannot force the signal to be positive in the engine (for the moment). A forecast post-processing is an option, as you mentioned.

Do you have a sample code that reproduces this ? I suppose/hope that the error is still acceptable.

Some signal transformations (log) force the signal to be positive at the end, by design. You can activate these (not the default).

mgiangreco commented 6 years ago

I'll see if I can get permission to share some anonymized data. I think the issue comes into play when the model chosen by PyAF has a negative sloping trend and a long prediction horizon. In that case the forecast can dip into negative.

antoinecarme commented 6 years ago

This is usually needed when the signal values are expected to positive (counts etc).

Think also of a way to force something like this to be always positive :

image

Here, there are a few points where the forecast is negative.

antoinecarme commented 6 years ago

by applying a "relu" rectifier (commonly used in ANNs, https://en.wikipedia.org/wiki/Rectifier_(neural_networks)), one can get the desired forecast, something like :

lEngine2.mOptions.mForecastRectifier = "relu"

image

antoinecarme commented 6 years ago

The negative forecasts can now be removed (set to zero) using the training option :

 cForecastEngine.mOptions.mForecastRectifier = "relu"