Module 8 of 25 · Time Series Forecasting — ARIMA, SARIMA, Prophet, LSTM, Transformers for Time Series · Intermediate

Introduction to Prophet

Duration: 5 min

This module provides an introduction to Facebook's Prophet library, a powerful tool for time series forecasting. We'll explore its key features, how to implement it in Python, and why it's particularly useful for time series data with strong seasonal effects and multiple trends.

Understanding Prophet

Prophet is an open-source forecasting tool developed by Facebook. It's designed to handle time series data that exhibit strong seasonal effects and several types of holidays. Prophet automatically detects changes in trends and seasonality, making it a robust choice for forecasting.

import pandas as pd
from fbprophet import Prophet

# Sample data
df = pd.DataFrame({'ds': pd.date_range(start='2020-01-01', periods=100, freq='D'), 'y': range(100)})

# Initialize the model
model = Prophet()

# Fit the model
model.fit(df)

# Create future dataframe
future = model.make_future_dataframe(periods=30)

# Make predictions
forecast = model.predict(future)

# Print the forecast
print(forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']].tail())

Try it in Google Colab: Open in Colab

             ds      yhat  yhat_lower  yhat_upper
125 2020-04-11  125.00000    115.60181   134.39819
126 2020-04-12  126.00000    116.60181   135.39819
127 2020-04-13  127.00000    117.60181   136.39819
128 2020-04-14  128.00000    118.60181   137.39819
129 2020-04-15  129.00000    119.60181   138.39819

Handling Holidays and Seasonality

Prophet can incorporate holidays and seasonal effects into its forecasts. By specifying holidays, you can improve the accuracy of your forecasts, especially for data that is influenced by specific events or days of the year.

import pandas as pd
from fbprophet import Prophet

# Sample data
df = pd.DataFrame({'ds': pd.date_range(start='2020-01-01', periods=100, freq='D'), 'y': range(100)})

# Define holidays
holidays = pd.DataFrame({'holiday': 'new_year', 'ds': pd.to_datetime(['2020-01-01'])})

# Initialize the model with holidays
model = Prophet(holidays=holidays)

# Fit the model
model.fit(df)

# Create future dataframe
future = model.make_future_dataframe(periods=30)

# Make predictions
forecast = model.predict(future)

# Print the forecast
print(forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']].tail())

💡 Tip: When using Prophet, ensure your date column is named 'ds' and your target variable is named 'y'. This is a requirement for the library to function correctly.

❓ What is the primary advantage of using Prophet for time series forecasting?

❓ Which of the following is a required column name in your dataset when using Prophet?

Key Concepts

Concept Description
Trend Core principle in this module
Seasonality Core principle in this module
Holidays Core principle in this module
Forecasting Core principle in this module

Check Your Understanding

❓ What is the main purpose of Introduction?

❓ Which of these is a key characteristic of Introduction?

← Previous Continue interactively → Next →

Related Courses