Prophet: Setting forecast goals then updating model/trend lines?

Created on 8 Oct 2018  路  5Comments  路  Source: facebook/prophet

Hi, is there a way to set a goal metric (e.g., daily sales) for some date in the future (say, $1 million in sales by December 20) and then fill in the "necessary" daily sales between now and that future date using existing trend lines/parameters in Prophet?

Restated another way:

Based on prior data, we can use Prophet to predict daily sales from today to any point in the future. Now suppose we want to set a goal of $1 million in sales by Dec. 20th. Can we update Prophet's models to generate the necessary daily sales between now and Dec 20th which we need to meet that goal?

Most helpful comment

Hey @bletham - I finally got around to working on this a couple weeks ago and it worked great. So great that I decided to write a Medium article about it - here's a draft. Would you mind checking it to make sure there's no obvious mistakes or inaccuracies in how I've described the Prophet functions/processes? If you don't have time, that's fine too. 馃憤

https://medium.com/@foundinblank/goal-oriented-forecasting-in-r-prophet-b79900c64ca6

All 5 comments

This is an interesting question but I'm not sure I grasp it fully.

Suppose I have data until the present, and I want to set a goal for Dec 20. If all I want to know is how many sales I need per day to get from my current value to my goal value, it would just be (goal - current) / 65 (the number of days between now and Dec 20).

But if I can rephrase the question a 3rd time, I'm wondering if what you really want to know is "What is a plausible path between the current and the goal value". That plausible path would be a Prophet forecast that ends up at the goal level, but also includes seasonality. That way as you move forward in time, if your sales/day drops below that average-needed computed above, you can know if this is an expected seasonal drop and we're still on track, or is this drop lower than the forecast that gets us to the goal.

You can get this with the m.predictive_samples(future) method in Python or predictive_samples(m, future) function in R. You can check the docstring for a description of the outputs (help(m.predictive_samples) in Py or ?predictive_samples in R). In Py, the output is a dictionary (we'll call it samples) and you'd be interested in samples['yhat']. future could be the output of m.make_future_dataframe, but the important thing is that it contains the dates between now and Dec 20, and includes Dec 20. Suppose there are ndates dates (rows) in future. samples['yhat'] will then be a numpy array of size ndates x nsamp, where nsamp is the input uncertainty_samples when you created the Prophet model (it defaults to 1000). Each of the columns of this array is a sample from the Prophet model posterior and can be considered a plausible forecast. Look through the columns and find the one whose value at the row corresponding to Dec 20 is the closest to your goal. That is a plausible path that goes from the present to your goal. You can track your performance relative to that to know if (according to the model posterior) you are still on-track.

Does that make sense? Is that about what you have in mind here?

That is exactly the answer I was looking for! Thank you. I'll go try it out.

Great, I'd be curious to hear how it turns out.

Hey @bletham - I finally got around to working on this a couple weeks ago and it worked great. So great that I decided to write a Medium article about it - here's a draft. Would you mind checking it to make sure there's no obvious mistakes or inaccuracies in how I've described the Prophet functions/processes? If you don't have time, that's fine too. 馃憤

https://medium.com/@foundinblank/goal-oriented-forecasting-in-r-prophet-b79900c64ca6

@foundinblank that's a great article, thanks for sharing! A really nicely worked example too.

After reading that and thinking about it some more, I did have one other thought on this issue, that I think would be complementary to the approach described here and in the article. The good thing about that approach is that it produces an actual forecast that leads to the goal, and can be used to set a running "target" like you do in the article. The one downside in using a single draw is that we're no longer able to incorporate the uncertainty in the posterior. In particular, suppose that at some point (call it t) we fall below the target forecast. Does this mean we can't reach the goal? We don't really know; we're behind "schedule" on this draw from the posterior, but maybe there is another draw (plausible forecast) that has a lower value at t but still makes the goal. One complementary measure that we might also want to track would be the probability of achieving the goal. This can be estimated by just counting the proportion of posterior samples that exceed the goal level, and as we update the forecast to include the lower-than-hoped value at t, we will be able to see how much that probability drops by.

One a similar note, one might consider doing a rather large number of posterior samples (like 10k instead of 1k) and then instead of selecting just the 1 closest to the goal, perhaps select all of them that are within some window of the goal, and then use the average of those as the target and use their quantiles to get some uncertainty estimate for the ranges of forecasted values that ultimately end up near the goal. (Although with Prophet you'd have to be careful with RAM when doing this since it builds a giant table storing the values for every sample at every future point, so you might have to break it up into a few calls and each time only store the samples that are within the window of the goal value).

Again, nice work!

Was this page helpful?
0 / 5 - 0 ratings