Hi I am trying to parallelize facebook-prophet to panel-timeseries. Each series are independent from each other so there should be no problem fitting all together. What I want to do is fit a prophet model to each series simultaneously. I tried below:
def prop(df):
prop_feat = pd.DataFrame(columns = ['ds', 'trend', 'yhat_lower', 'yhat_upper', 'trend_lower', 'trend_upper',
'daily', 'daily_lower', 'daily_upper', 'weekly', 'weekly_lower',
'weekly_upper', 'yhat'])
for t,n in tqdm(enumerate(range(100, len(df)))):
m = Prophet(yearly_seasonality=False, weekly_seasonality=8, daily_seasonality=10, changepoint_prior_scale=0.05, changepoint_range = 1)
m.fit(df.iloc[:n, :].drop(["O2_ID", ], axis=1))
future = m.make_future_dataframe(periods=1, freq="h")
forecast = m.predict(future)
prop_feat.loc[t, :] = forecast.loc[len(forecast)-1, ['ds', 'trend', 'yhat_lower', 'yhat_upper', 'trend_lower', 'trend_upper',
'daily', 'daily_lower', 'daily_upper', 'weekly', 'weekly_lower',
'weekly_upper', 'yhat']]
prop_feat["ds"] = prop_feat.ds - pd.Timedelta("1h")
return pd.merge(df, prop_feat, on="ds")
pandarallel.initialize()
z = df_trial.groupby("O2_ID", as_index=False).parallel_apply(prop)
After it ran several iterations, it gave the following error:
TypeError: _is_indexed_like() missing 1 required positional argument: 'axis'
Anyone can help me to solve the error. Or the propose different approach to achieve what I am trying to do?
PS: Following worked fine: z = df_trial.groupby("O2_ID", as_index=False).apply(prop)
Edit:
Example data, first 5 rows of the data-frame: