Ask Your Question
2

Attempting to use Facebook's Prophet model with regressors to make forecasts.

asked 2022-05-26 11:00:00 +0000

lakamha gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2021-06-11 05:00:00 +0000

ladyg gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-05-26 11:00:00 +0000

Seen: 10 times

Last updated: Jun 11 '21