Search code examples
pythonfacebook-prophet

Facebook prophet, non daily data in Python


I have data at a half hourly level over a few nonths. It's in the form:

05/10/2017 00:00:00,    116.297
05/10/2017 00:30:00,    7.3748
05/10/2017 01:00:00,    -94.8402
05/10/2017 01:30:00,    41.0546
05/10/2017 02:00:00,    206.3658
05/10/2017 02:30:00,    -283.0569
05/10/2017 03:00:00,    -656.2
05/10/2017 03:30:00,    631.2834

I'd like to make a forecast for the next 24 hours (so 48 half hours). My code seems to give a forecast for much longer than this. See plot:

enter image description here

Here it is:

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from fbprophet import Prophet

# Load data
file_name = "test_data.csv"
df = pd.read_csv(file_name,parse_dates=[0])

#Fit the model
m = Prophet().fit(df)

#Make predictions
future = m.make_future_dataframe(periods=48, freq=H)

fcst = m.predict(future)
m.plot(fcst)
plt.show()

Am I not setting the make_future_dataframe method correctly?


Solution

  • You wanted for next 24 hours i.e. 1 day (48 half hours)
    You should set freq='30min' in case if you want to get half hourly predictions.

    future = m.make_future_dataframe(periods=48, freq='30min')

    This future variable will have the next 48 half hourly periods.

    I hope this would help you.