prophet icon indicating copy to clipboard operation
prophet copied to clipboard

Option to Log Time Series

Open vruvora opened this issue 8 years ago • 7 comments

Would it be possible to specify if we can logy as an option for Prophet model, e.g.

Prophet(n_changepoints=25, logy=True)

Happy to work on this is as a PR if people are interested.

vruvora avatar Apr 06 '18 18:04 vruvora

It would be good. I vote for it.

hassheh avatar Apr 10 '18 11:04 hassheh

I think the main effort here would be to apply exp() everywhere needed on the outputs. I think these would be: predict, and after the call to predict_seasonal_components inside plot_weekly, plot_yearly, and plot_seasonality.

I think that the effort for taking log on the input and then exp on the output is pretty low, I think the main benefit of having it built-in would be in the components plot showing the seasonality in the real-space, not log-space. Is that accurate or are there other things that can't be done by taking exp() of the prediction df? I'm a bit on the fence if it's better to see it in log-space or after the exp() - I feel like seeing it with the log transform in which it was actually fit would make it easier to debug model issues. But if other people find this valuable then go ahead and put it in!

One note though is that if the log transform is being primarily used to get multiplicative seasonality, I'm really hopeful that will be in without transform soon.

bletham avatar Apr 11 '18 04:04 bletham

Multiplicative seasonality is now in the v0.3 branch without requiring any transforms. If anyone is using log transform to get multiplicative seasonality, feel free to try it out by installing that branch per my comment in #254.

bletham avatar May 16 '18 20:05 bletham

I'm guessing multiplicative seasonality is the main reason for taking the log, and so now that that is natively supported I'd prefer to not have this built-in just for simplicity. But if there are other frequent uses please re-open and let's discuss.

bletham avatar May 25 '18 21:05 bletham

I have been reading that log transformation is needed when variance of the error is correlated with time.

Is this something the model takes into account and can we ignore that part?

denizn avatar May 31 '18 00:05 denizn

Hi, as per here in #492, was anything developed to apply exp() to the data points used within the plot?

As @bletham said, the log transform is easy to do outside of Prophet, as is applying exp() to yhat and other predictive terms. However, the datapoints are not so easy to apply exp() to, resulting in plots like the below.

image

I am taking a log of the data not for multiplicative seasonality, but to ensure predictions are >0.

anqus avatar Mar 27 '20 11:03 anqus

For making a plot: I think the easiest thing to do would probably be to copy out and modify the plotting code. It really isn't very much code to produce this plot, it's all here: https://github.com/facebook/prophet/blob/3c69ce3312fcf91d15fd7e56812aa28cabf6f9f2/python/fbprophet/plot.py#L65-L88

And basically you would just want to copy this out and then change it to

ax.plot(m.history['ds'].dt.to_pydatetime(), np.exp(m.history['y']), 'k.')

bletham avatar Mar 31 '20 17:03 bletham