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

Preface

In 2017, Facebook released their Prophet software as open source. This powerful tool was developed by Facebook engineers because their analysts were becoming overwhelmed with the number of business forecasts demanded by managers. The developers of Prophet wanted to simultaneously solve two problems: a) completely automatic forecasting techniques are too brittle and inflexible to handle additional knowledge, and b) analysts who are consistently able to produce high-quality forecasts are rare and require extensive expertise. Prophet successfully solves both of these problems.

Prophet was designed so that forecasts produced with no parameter tuning or other optimization are usually very high quality, but with just a little bit of training, anyone can intuitively tweak the model and increase performance dramatically.

Starting from the most basic model and advancing to the deepest technical dives into Prophet's inner workings, this book will teach you everything there is to know about Facebook's Prophet. Many advanced features not even covered by the official documentation are discussed here, with complete working examples for every topic covered. This book is not intended to provide you the ability to build a Prophet clone from scratch, but it will teach you to use Prophet just as well as, if not better than, Facebook's own highly-trained engineers.

Who this book is for

This book is for anyone who wants to use Facebook's Prophet to improve their forecasts. Data scientists and data analysts, machine learning engineers and software engineers, and even business managers will benefit from the topics covered in this book. All that is required is that the reader is comfortable with working in either Python or R, or is willing to learn how. The business manager who is familiar with Python can follow the examples included in this book and will learn how to modify them to fit their own use cases; the data scientist will gain a more technical understanding of what Prophet is doing under the hood and how it works. However, this book is intended mostly as a how-to guide. It will not provide a fully rigorous explanation of the math and statistics that underpin the equations controlling Prophet. For that, I suggest reading the original Prophet paper: Taylor SJ, Letham B. 2017. Forecasting at scale. PeerJ Preprints 5:e3190v2 (https://doi.org/10.7287/peerj.preprints.3190v2).

What this book covers

Chapter 1, The History and Development of Time Series Forecasting, will teach you about the earliest efforts to understand time series data and the main algorithmic developments up to the present day.

Chapter 2, Getting Started with Facebook Prophet, will walk you through the process of getting Prophet running on your machine, and then will test your installation by building your first model.

Chapter 3, Non-Daily Data, will cover how to modify the approach taken in the previous chapter in order to handle data that is recorded on a scale other than daily, so that you will be set up to work through all of the examples in later chapters.

Chapter 4, Seasonality, will discuss all of the ways to control seasonality in Prophet. Seasonality is one of the building blocks of Prophet models and contains the most control parameters, so this chapter is the longest but also one of the most important.

Chapter 5, Holidays, will teach you how to add the effect of holidays to your forecast. You will learn how to include a basic set of default holidays, how to change that set for different regions, how to add your own custom holidays, and how to control the strength of the effect.

Chapter 6, Growth Modes, will describe the three growth modes a trend line in Prophet can follow: linear, logistic, and flat. You will learn which scenarios to apply these modes to and observe what effect they have on your future forecasts.

Chapter 7, Trend Changepoints, will talk about how to control the rigidity of your final model. You will learn how to make a flexible model that can change direction often, or a rigid model that follows a constant line, why you may choose one or the other, and the effect this has on the uncertainty of your model with future data.

Chapter 8, Additional Regressors, will teach you how to include additional columns of data in your model. Similar to multi-variate regression, Prophet is able to combine multiple input vectors in a predictive forecast.

Chapter 9, Outliers and Special Events, will show you the two types of problems that outliers can cause in a Prophet model and will teach you several automated techniques for identifying outliers and how to handle them with Prophet.

Chapter 10, Uncertainty Intervals, will cover how to quantify the uncertainty in your model using different statistical methods, what the benefits and drawbacks of each method are, and how to visualize the amount of risk in your model.

Chapter 11, Cross-Validation, will teach you how to perform cross-validation in Prophet. You may already be familiar with cross-validation techniques in machine learning, but with time series data a different approach is needed. This chapter will teach you that approach and how to implement it in Prophet.

Chapter 12, Performance Metrics, will build upon the previous chapter and introduce the performance metrics Prophet features. You will learn how to combine cross validation with your chosen metric of performance to perform a grid search and optimize your model to gain the highest predictive accuracy.

Chapter 13, Productionalizing Prophet, is the final chapter and will teach you some additional techniques that will come in handy when using Prophet in a production environment. You will learn how to save your models for later use, how to update models as new data comes in, and how to use Prophet's Plotly plot functions to build highly interactive charts suitable for sharing on a web-based dashboard.

To get the most out of this book

To run the code examples in this book, you will need Python 3.x installed. All examples in this book were made using Prophet version 0.71 in Jupyter Notebooks. MacOS, Windows, and Linux are all supported. Although all examples in this book will be written in Python, everything is also fully compatible with R and you may use that language if you prefer, although this book will not cover R syntax. Please refer to the official Prophet documentation for R syntax (https://facebook.github.io/prophet/).

Chapter 2, Getting Started with Facebook Prophet will walk you through installing Facebook Prophet, and installing either Anaconda or Miniconda is strongly recommended in order to correctly install all of Prophet's dependencies. It is possible to install Prophet without using Anaconda, but it can be very difficult depending upon the specific configuration of your machine, and this book will assume Anaconda will be used.

In order to follow the examples, you must at least be familiar with the pandas library for data processing and Matplotlib for making plots. In a few cases, the numpy library will be used to simulate random data but following the examples will not require that you know the NumPy syntax. All of these libraries will be installed automatically as Prophet dependencies, if not already installed. All datasets are hosted and can be downloaded from this book's GitHub repo here: https://github.com/PacktPublishing/Forecasting-Time-Series-Data-with-Facebook-Prophet.

Prophet supports parallelization with Dask but, while setting Prophet up to run on a Dask cluster will be covered, installing and using Dask is beyond the scope of this book. Similarly, this book will cover how to build interactive Prophet visualizations in Plotly but putting those together into a Dash dashboard will be left up to the reader to learn elsewhere.

If you are using the digital version of this book, we advise you to type the code yourself or access the code via the GitHub repository (link available in the next section). Doing so will help you avoid any potential errors related to copy/pasting of code.

Download the example code files

You can download the example code files for this book from GitHub at https://github.com/PacktPublishing/Forecasting-Time-Series-Data-with-Facebook-Prophet. In case there's an update to the code, it will be updated on the existing GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Download the color images

We also provide a PDF file that has color images of the screenshots/diagrams used in this book. You can download it here: https://static.packt-cdn.com/downloads/9781800568532_ColorImages.pdf.

Conventions used

There are a number of text conventions used throughout this book.

Code in text: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "The make_future_dataframe method requires us to specify the number of days we intend to forecast out."

A block of code is set as follows:

model = Prophet()
model.fit(df)
future = model.make_future_dataframe(periods=365)
forecast = model.predict(future)
fig = model.plot(forecast)
plt.show()

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

model = Prophet()
model.fit(df)
future = model.make_future_dataframe(periods=60, freq='MS')
forecast = model.predict(future)
fig = model.plot(forecast)
plt.show()

Any command-line input or output is written as follows:

pip install pystan
pip install fbprophet

Bold: Indicates a new term, an important word, or words that you see on screen. For example, words in menus or dialog boxes appear in the text like this. Here is an example: "In the following seasonality plot, I've used the Toggle Spike Lines and Compare Data buttons from this toolbar to add further information to the hover tooltip, seen here:"

Tips or important notes

Appear like this.

Get in touch

Feedback from our readers is always welcome.

General feedback: If you have questions about any aspect of this book, mention the book title in the subject of your message and email us at customercare@packtpub.com.

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/support/errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.

Piracy: If you come across any illegal copies of our works in any form on the Internet, we would be grateful if you would provide us with the location address or website name. Please contact us at copyright@packt.com with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Reviews

Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!

For more information about Packt, please visit packt.com.

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