facebook / prophet

Tool for producing high quality forecasts for time series data that has multiple seasonality with linear or non-linear growth.
https://facebook.github.io/prophet
MIT License
18.38k stars 4.52k forks source link

How to deal with negative results? #331

Closed pocakka closed 6 years ago

pocakka commented 7 years ago

Hello :) My sample data is:

"ds","y"
2017-01-01,1000
2017-01-02,900
2017-01-03,800
2017-01-04,700
2017-01-05,600
2017-01-06,500
2017-01-07,400
2017-01-08,300
2017-01-08,200

My code is:

df = pd.read_csv('./examples/sample-test.csv')
df['y'] = np.log(df['y'])
df.head()
m = Prophet(changepoint_prior_scale=0.011)
m.fit(df);
future = m.make_future_dataframe(periods=365)
future.tail()
forecast = m.predict(future)
forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']].tail()
m.plot(forecast, xlabel='Date', ylabel='Change')
plt.show()

The result: https://imgur.com/a/LWA99

I think, in the real life there isn't negative trading volume, just "zero". Is it possible make the negative results to zero? Made with PS a simple example: https://imgur.com/a/LNAfQ

Regards

rpanai commented 7 years ago

If you need non-positive values you can run

import numpy as np
forecast["y"] = np.where(forecast["y"]<0,0,forecast["y"])

and eventually the same for yhat_lower and yhat_upper. You are eventually going to miss some infos without these values. I tend to don't modify the forecast dataframe and use 0 whenever i need to take decisions with the forecasts.

bletham commented 7 years ago

You can put in a lower saturating bound by passing growth='logistic' to Prophet() and including it in the dataframe - described in detail near the bottom here: https://facebook.github.io/prophet/docs/saturating_forecasts.html

This does, however, require you to also specify a saturating upper bound - a value that you are sure your time series should never be higher than. Having a lower bound without an upper bound is on the to-do list in #307, and I'd expect should make the next version.

bletham commented 6 years ago

I'm going to close this out, and any discussion on the general issue of trends that saturate on only one end can be had in #307.