facebook / prophet

Tool for producing high quality forecasts for time series data that has multiple seasonality with linear or non-linear growth.
https://facebook.github.io/prophet
MIT License
18.44k stars 4.53k forks source link

Does warm start take more time to predict? (using weekly data) #1853

Open SiddharthMetta opened 3 years ago

SiddharthMetta commented 3 years ago

Working on weekly data to predict for the next 1 week and I observed that warm-start takes more time to predict (and even fitting at times).? Is it normal or something to do with the code or data?

 with open('serialized_model.json', 'r') as fin:
        m1 = model_from_json(json.load(fin)) 

  m2 = Prophet(weekly_seasonality=True, yearly_seasonality='auto', n_changepoints=30,
       daily_seasonality=True, seasonality_mode = 'multiplicative', changepoint_prior_scale=0.1, changepoint_range= 0.6)

  m2.fit(train_df, init=stan_init(m1))
  future = m2.make_future_dataframe(periods=1, freq = "W")

  forecast = m2.predict(future)

  res = forecast.tail(1).yhat.values[0]

  #out.append(res)
  train_df = train_df.append(df.iloc[count+106])

  m2.fit_kwargs['init']['delta'] = m2.fit_kwargs['init']['delta'].tolist()
  m2.fit_kwargs['init']['beta'] = m2.fit_kwargs['init']['beta'].tolist()
  with open('serialized_model.json', 'w') as fout:
      json.dump(model_to_json(m2), fout)
bletham commented 3 years ago

It's definitely possible for fitting to be slower with warm-starting. As discussed in the docs, if there is a large change to the data, then the state of the last model may be a poor initialization to the new model, and you would be better off just using the not-warm-started default initialization. It really just depends on how close the parameters of m1 are to the optimal parameters of m2.

For predict, whether or not the model was warm-started should make no difference to predict time. If you're seeing this, I'd be interested if you could create a reproducible example using %timeit like in the docs on warm starting. The only way predict time could be affected is if warm-starting causes the model fitting to converge to a different set of parameters and something about those parameters makes the predict slower, but I don't think that is especially likely.