Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 224
Anthony W Avatar asked Apr 06 '18 16:04

Anthony W


2 Answers

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.

like image 193
Shree Divya Avatar answered Oct 21 '22 15:10

Shree Divya


Here is a reference to the acceptable freq parameter aliases

Which means this should work for you

future = m.make_future_dataframe(periods=24, freq='H')

Try setting periods=24 since freq is now specified in hours

like image 7
Josh Wilkins Avatar answered Oct 21 '22 17:10

Josh Wilkins