prophet icon indicating copy to clipboard operation
prophet copied to clipboard

Constraining the Time Series to be Positive

Open vruvora opened this issue 8 years ago • 3 comments

Are there ways we can constrain the time series to be positive such that it only learns positive values? Currently positive samples negatively on time series that should be constrained to be >= 0.

vruvora avatar Aug 02 '18 20:08 vruvora

You could try sampling your y from a left-0 truncated Normal distribution by changing the code here: https://github.com/facebook/prophet/blob/master/python/stan/unix/prophet.stan#L112

Another idea would be to change the stan code to use exponentials instead of laplacians to generate the weights for the model (and half-normals instead of normals). This would force GAM coefficients to be >=0 (so if your regressors are strictly positive you will achieve positive results). Yet, in theory seasonality could still make your time series dip below 0 (depending on your data).

luke14free avatar Aug 05 '18 13:08 luke14free

Hmm that requires having our own version of Prophet running. Basic solution would be just to log the timeseries.

vruvora avatar Aug 05 '18 17:08 vruvora

How about taking log transformation of you data and then exp of your predictions. Those values would be positive for sure. Not sure if all intervals would behave as expected but yhat values might be useful.

vhpietil avatar Aug 06 '18 04:08 vhpietil