Wednesday, 8 May 2019

Facebook Prophet: Providing different data sets to build a better model

My data frame looks like that. My goal is to predict event_id 3 based on data of event_id 1 & event_id 2

ds tickets_sold y event_id
3/12/19 90  90  1
3/13/19 40  130 1
3/14/19 13  143 1
3/15/19 8   151 1
3/16/19 13  164 1
3/17/19 14  178 1
3/20/19 10  188 1
3/20/19 15  203 1
3/20/19 13  216 1
3/21/19 6   222 1
3/22/19 11  233 1
3/23/19 12  245 1
3/12/19 30  30  2
3/13/19 23  53  2
3/14/19 43  96  2
3/15/19 24  120 2
3/16/19 3   123 2
3/17/19 5   128 2
3/20/19 3   131 2
3/20/19 25  156 2
3/20/19 64  220 2
3/21/19 6   226 2
3/22/19 4   230 2
3/23/19 63  293 2

I want to predict sales for the next 10 days of that data:

ds  tickets_sold y event_id
3/24/19 20  20  3
3/25/19 30  50  3
3/26/19 20  70  3
3/27/19 12  82  3
3/28/19 12  94  3
3/29/19 12  106 3
3/30/19 12  118 3

So far my model is that one. However, I am not telling the model that these are two separate events. However, it would be useful to consider all data from different events as they belong to the same organizer and therefore provide more information than just one event. Is that kind of fitting possible for Prophet?

# Load data
df = pd.read_csv('event_data_prophet.csv')
df.drop(columns=['tickets_sold'], inplace=True, axis=0)
df.head()

# The important things to note are that cap must be specified for every row in the dataframe,
# and that it does not have to be constant. If the market size is growing, then cap can be an increasing sequence.
df['cap'] = 500

# growth: String 'linear' or 'logistic' to specify a linear or logistic trend.
m = Prophet(growth='linear')
m.fit(df)

# periods is the amount of days that I look in the future
future = m.make_future_dataframe(periods=20)
future['cap'] = 500
future.tail()

forecast = m.predict(future)
forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']].tail()

fig1 = m.plot(forecast)



from Facebook Prophet: Providing different data sets to build a better model

No comments:

Post a Comment