1

I need to forecast with prophet in a "rolling" way. Just to give you the idea, considering a df of shape (2400,2), I want to perform something like:

def forecast(dataframe):

    m = Prophet()
    m.fit(dataframe)
    future = m.make_future_dataframe(
             periods=24, freq="H")
    forecast = m.predict(future)

    return forecast['yhat'][-1]

df['yhat'] = df[['ds','y']].rolling(240).apply(forecast)

Is there a smart way to do that?

RevFlux
  • 11
  • 2

1 Answers1

0

Done in this way, maybe there is a better way:

def forecast(data, prds):

    data.name='y'
    data.reset_index(drop=True, inplace=True)

    df = pd.DataFrame()
    df['ds'] = pd.date_range(start='1/1/2020', periods=len(data), freq="H")

    df=df.merge(data, left_index=True, right_index=True)

    m = Prophet()
    m.fit(df)
    future = m.make_future_dataframe(periods=prds, freq="H")
    forec = m.predict(future)

    prediction = forec['yhat'].iloc[-1]

    return prediction

dataframe['yhat'] = dataframe['y'].rolling(240).apply(forecast, args=(24,))

RevFlux
  • 11
  • 2