Prophet
Prophet is an automatic forecasting procedure developed by Facebook. It is designed for analyzing time series that exhibit strong seasonal effects and has several seasons of historical data. The current version is 1.3.0, and it maintains a regular release cadence with frequent updates and bug fixes.
Warnings
- breaking The official package name changed from `fbprophet` to `prophet`. Projects still using `fbprophet` will encounter import errors and miss out on updates.
- gotcha Installation of `prophet` often requires a C++ compiler and specific environment setup due to its `cmdstanpy` dependency. Users on Windows or macOS might need to install development tools (e.g., Build Tools for Visual Studio, Xcode Command Line Tools).
- gotcha Prophet expects the 'ds' column to contain naive (timezone-unaware) datetime objects, ideally in UTC. Providing timezone-aware datetimes can lead to unexpected behavior or errors.
- gotcha Prophet has strict dependencies on specific versions of `pandas` and `numpy`. Version conflicts can cause runtime errors or unexpected behavior. While recent versions (1.3.0) aim to broaden compatibility, it remains a common issue.
Install
-
pip install prophet
Imports
- Prophet
from prophet import Prophet
Quickstart
import pandas as pd
from prophet import Prophet
# Create a sample DataFrame with 'ds' (datetime) and 'y' (value) columns
data = {
'ds': pd.to_datetime(['2017-01-01', '2017-01-02', '2017-01-03', '2017-01-04', '2017-01-05',
'2017-01-06', '2017-01-07', '2017-01-08', '2017-01-09', '2017-01-10']),
'y': [10, 12, 15, 13, 17, 18, 20, 22, 25, 23]
}
df = pd.DataFrame(data)
# Instantiate and fit the Prophet model
model = Prophet()
model.fit(df)
# Create a future DataFrame for predictions (e.g., next 3 days)
future = model.make_future_dataframe(periods=3)
# Make predictions
forecast = model.predict(future)
# Print the last few rows of the forecast
print(forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']].tail())