Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
533 views
in Technique[技术] by (71.8m points)

python - Getting error from pandarallel with groupby, while trying to parallelize prophet to panel-timeseries

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:

First 5 rows


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...