Forecasting Using Facebook’s Prophet Library | by Christoph... [Link]
1 of 11 11/8/2021, 2:24 PM
Forecasting Using Facebook’s Prophet Library | by Christoph... [Link]
2 of 11 11/8/2021, 2:24 PM
Forecasting Using Facebook’s Prophet Library | by Christoph... [Link]
from [Link] import drive
[Link](‘/content/drive’, force_remount=True)
from fbprophet import Prophet
import pandas as pd
3 of 11 11/8/2021, 2:24 PM
Forecasting Using Facebook’s Prophet Library | by Christoph... [Link]
df = pd.read_csv(‘../datasets/air_passenger.csv’)
[Link]()
[Link] = [‘ds’, ‘y’]
4 of 11 11/8/2021, 2:24 PM
Forecasting Using Facebook’s Prophet Library | by Christoph... [Link]
df[‘ds’] = pd.to_datetime(df[‘ds’])
# defining the number of observations we want to
predict
nobs = 12
train = df[:-nobs]
test = df[-nobs:]
print(f"Length of dataframe: {len(df)}\n"
f"Length of train set: {len(train)}\n"
f"Length of test set: {len(test)}")
5 of 11 11/8/2021, 2:24 PM
Forecasting Using Facebook’s Prophet Library | by Christoph... [Link]
# Creating an instance of the Prophet model
prophet = Prophet()
# fitting Prophet model to the train set
[Link](train)
future = prophet.make_future_dataframe(periods=nobs,
freq=’MS’)
6 of 11 11/8/2021, 2:24 PM
Forecasting Using Facebook’s Prophet Library | by Christoph... [Link]
forecast = [Link](future)
fig1 = [Link](forecast)
from [Link] import add_changepoint_to_plot
fig1 = [Link](forecast)
# viewing the points in time where the trajectory of
the price index changed
a = add_changepoints_to_plot([Link](), prophet,
7 of 11 11/8/2021, 2:24 PM
Forecasting Using Facebook’s Prophet Library | by Christoph... [Link]
forecast)
8 of 11 11/8/2021, 2:24 PM
Forecasting Using Facebook’s Prophet Library | by Christoph... [Link]
from [Link].eval_measures import rmse
# Remember nobs = 12
9 of 11 11/8/2021, 2:24 PM
Forecasting Using Facebook’s Prophet Library | by Christoph... [Link]
y_pred = [Link][-nobs:][‘yhat’]
y_true = test['y']
rmse(y_pred, y_true)
10 of 11 11/8/2021, 2:24 PM
Forecasting Using Facebook’s Prophet Library | by Christoph... [Link]
11 of 11 11/8/2021, 2:24 PM