Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To use Facebook's Prophet model with regressors to make forecasts, you can follow the steps below:

  1. Import the required libraries:
import pandas as pd
from fbprophet import Prophet
  1. Load the data:
df = pd.read_csv('data.csv')
  1. Create the Prophet model:
model = Prophet()
  1. Add the regressors to the model:
model.add_regressor('regressor_1')
model.add_regressor('regressor_2')
  1. Fit the model and make predictions:
model.fit(df)

future_df = model.make_future_dataframe(periods=365)
future_df['regressor_1'] = [1, 2, ..., 5]
future_df['regressor_2'] = [10, 20, ..., 50]

forecast = model.predict(future_df)
  1. Visualize the forecast:
model.plot(forecast)

This code assumes that you have a CSV file called 'data.csv' with columns 'ds' (the date column) and 'y' (the target variable column). The regressors are assumed to be called 'regressor1' and 'regressor2'.

You can replace the regressors and target variable columns names with whatever you have in your dataset.

Note that Prophet handles missing values automatically, so you don't need to worry about that as long as your dataset is reasonably complete.