-
Notifications
You must be signed in to change notification settings - Fork 4.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow constant trend #614
Comments
Have you looked at |
@mcaviel thank you. I have tried but turn down |
I am thinking about taking the mean value of predicted I tried this one but it is not: fcst["yhat_upper"] - fcst["trend_upper"]*fcst["multiplicative_terms_upper"]*( fcst["additive_terms_upper"]+fcst["daily_upper"] + fcst["weekly_upper"]) |
This is a challenging time series for Prophet since it does not conform very well to the model. The multiplicative Prophet model is that Daily seasonality that depends on weekly seasonality is one challenge with this time series. The other challenge is that the middle week has stronger effects than the other two weeks. Since the daily and weekly seasonalities are constant, the only way for the model to have higher values on the middle week is via the trend. You could try to resolve the issue with the trend decreasing in the future by using logistic growth and setting a |
Oh, and I forgot to mention - there is currently no way to specify a constant trend. I think there is an issue open for this but can't find it at the moment. |
@bletham thank you so much for the concrete information. And you are right, I realized that my data does not conform very well to the model, especially if I want to make a constant trend. However, it is okay that the "constant-trend model" does not fit the data very well. Because what I am doing is an anomaly detection project, and actually the middle week should be considered to be anomaly. That is what I mean, even seems like there is a trend, but it actually is not. |
That's reasonable, and a flat trend seems like a good thing to support in the future. In the meantime, the only way this could be done would be by modifying the Stan code to put a very tight prior on |
@bletham Thank you. Hope we can have this new feature in the future. |
Now with #501, is there a easy way (changing k) to make this possible ? Could you give some hint how to do that ? |
I believe Ben means we need to set the prior scale for prophet/python/stan/unix/prophet.stan Line 109 in a3ae471
Please correct me if I'm wrong @bletham . |
@sammo Yes, k is the initial slope and so a very tight prior will force it to be very close to 0. And then if n_changepoints=0, it will stay flat at 0. There is another parameter m that sets the y intercept and that will still be fit. I'd expect that to work well for the linear trend. For the logistic I have less intuition - there isn't a y-intercept term in the logistic growth function rather there is an x offset, so I think taking k close to 0 would force the trend to be 0.5 * cap? If this is a bad fit then that would definitely mess up the optimizer. If you're anyway modifying Stan code, then there's a cleaner way of doing this by just directly editing the trend function here: prophet/python/stan/unix/prophet.stan Line 74 in a3ae471
If you replace that with
then it will fit a flat trend with y-intercept m (which is fit). The same modification has to be made in the Py/R definition of the trend, which is used at predict time: prophet/python/fbprophet/forecaster.py Line 1199 in a3ae471
That entire function would be replaced by
to match the modified Stan. That requries 2 edits but doesn't make you have to worry about super tight priors or inference issues that may come as a result. |
@bletham thanks for the thorough explanation. That makes sense. There might be a few cases where this would be helpful for some of the time series I'm working with so I may use it... |
I am not sure how elegant it is, but you can get prophet to force a constant trend by setting growth='logistic', cap = last * (1 + epsilon), floor = last * (1 - epsilon), where last is the latest y-value you have, and epsilon is a very small number |
Just adding a +1 that being able to manually configure the growth curve would be great. I'm also attempting to use Prophet for anomaly detection and find that often, the anomalous behavior leads to unwanted growth trends. I appreciate that this is great functionality for forecasting but not so great for anomaly detection (which is not the intended case for Prophet). But if I could fix the trend to be zero, then the anomalous period would be easier to identify and Prophet would very applicable to anomaly detection too. |
@Rosina9700 Ive just submitted PR #1466 for this - although my working solution sets a flat growth rather than allowing tightening of the growth prior, but seems like thats what people are keen on anyway. |
@ryankarlos and @bletham thanks for tackling this and getting it merged! Looking forwards to trying it out! |
@Rosina9700 if you do try this out and have a nice example that you can share the data for, please do post it so we could potentially use it in the documentation! |
I'm leaving this open until it gets ported to R too. |
This feature is now in R and in CRAN in the latest v1.0 release. |
Hi,
Is there a way to force the trend to be flat? My data has strong daily and weekly seasonality, rather than a strong trend change pattern. Is there a way to make a flat trend on model?
example:
right now the trend change is too strong, so if I use the current model to predict, prediction will go down (because of the trend). I want to avoid this by making the trend flat. What really matters in my data should only be the seasonalities.
The text was updated successfully, but these errors were encountered: