Reader small image

You're reading from  Forecasting Time Series Data with Facebook Prophet

Product typeBook
Published inMar 2021
Reading LevelBeginner
PublisherPackt
ISBN-139781800568532
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
Greg Rafferty
Greg Rafferty
author image
Greg Rafferty

Greg Rafferty is a data scientist in San Francisco, California. With over a decade of experience, he has worked with many of the top firms in tech, including Google, Facebook, and IBM. Greg has been an instructor in business analytics on Coursera and has led face-to-face workshops with industry professionals in data science and analytics. With both an MBA and a degree in engineering, he is able to work across the spectrum of data science and communicate with both technical experts and non-technical consumers of data alike.
Read more about Greg Rafferty

Right arrow

Chapter 7: Trend Changepoints

During the development of Prophet, the engineering team recognized that real-world time series will frequently exhibit abrupt changes in their trajectories. As a fundamentally linear regression model, Prophet would not be capable of capturing these changes without special care being taken. You may have noticed in the previous chapters, however, that when we plotted the forecast components in our examples, the trend line was not always perfectly straight. Clearly, the Prophet team has developed a way for Prophet to capture these bends in the linear model. The locations of these bends are called changepoints.

Prophet will automatically identify these changepoints and allow the trend to adapt appropriately. However, there are several tools you can use to control this behavior if Prophet is underfitting or overfitting these rate changes. In this chapter, we'll look at Prophet's automatic changepoint detection to provide you with an understanding...

Technical requirements

The data files and code for examples in this chapter can be found at https://github.com/PacktPublishing/Forecasting-Time-Series-Data-with-Facebook-Prophet.

Automatic trend changepoint detection

Trend changepoints are locations in your time series where the trend component of the model suddenly changes its slope. There could be many reasons why these changepoints occur, depending upon your dataset. For example, Facebook developed Prophet to forecast their own business problems; they may be modeling the number of daily active users and see a sudden change of trend upon the release of a new feature.

Airline passenger numbers may suddenly change as economies of scale allow much cheaper flights. The trend of carbon dioxide in the atmosphere was relatively flat for tens of thousands of years, but then suddenly changed during the Industrial Revolution.

From our work with the Divvy dataset in previous chapters, we saw a slow-down of growth after approximately two years. Let's take a closer look at this example to learn about automatic changepoint detection.

Default changepoint detection

Prophet sets changepoints by first specifying...

Regularizing changepoints

As stated earlier, Prophet will place 25 potential changepoints in the first 80% of the time series by default. To control Prophet's automatic changepoint detection, you can modify both of these values with the n_changepoints and changepoint_range arguments during model instantiation. For example, changing the number of potential changepoints to five is done like this:

model = Prophet(seasonality_mode='multiplicative',
                yearly_seasonality=4,
                n_changepoints=5)

This results in five evenly spaced potential changepoints in the first 80% of the data, as shown here:

Figure 7.5 – Five potential changepoints

Or, you could instead force all 25 changepoints to lie not in the first 80% of data, but rather in the first 50%:

model...

Specifying custom changepoint locations

James Rodríguez is a Colombian soccer player who played in both the 2014 and 2018 World Cups. He was a standout player in both Cups but won the Golden Boot award in 2014 for scoring more goals than any other player in the competition. I chose his account because it exhibits some very interesting behavior that would be extremely difficult to model without changepoints:

Figure 7.10 – James Rodríguez's Instagram likes per day

The number of likes his Instagram posts get is gradually increasing over time. But there are two notable spikes, in the summers of 2014 and 2018 when he was playing in the World Cup. It is clear that the spike in 2014 resulted in a significant trend change. The number of likes his posts were getting increased dramatically during the World Cup and dropped afterwards, but not to the same baseline as before. He had gained a large number of new followers during this period and consistently...

Summary

In this chapter, you learned how to control the fit of the trend line by using changepoints. First, you used Divvy data to see how Prophet automatically selects potential changepoint locations and how you can control this by modifying the default number of potential changepoints and the changepoint range.

Then you learned a more robust way to control Prophet's changepoint selection through regularization. Just as with seasonality and holidays, changepoints are regularized by setting the prior scale. You then looked at the Instagram data of James Rodríguez and learned how to model the increase in likes per post he received both during and after the World Cups of 2014 and 2018. Finally, you learned how to blend these two techniques and enrich an automatically selected grid of potential changepoints with your custom changepoint locations.

In the next chapter, we will again look at the Divvy data, but this time we'll include the additional columns for temperature...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Forecasting Time Series Data with Facebook Prophet
Published in: Mar 2021Publisher: PacktISBN-13: 9781800568532
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Greg Rafferty

Greg Rafferty is a data scientist in San Francisco, California. With over a decade of experience, he has worked with many of the top firms in tech, including Google, Facebook, and IBM. Greg has been an instructor in business analytics on Coursera and has led face-to-face workshops with industry professionals in data science and analytics. With both an MBA and a degree in engineering, he is able to work across the spectrum of data science and communicate with both technical experts and non-technical consumers of data alike.
Read more about Greg Rafferty