prophet icon indicating copy to clipboard operation
prophet copied to clipboard

Extracting component data-frames

Open abdelatifsd opened this issue 5 years ago • 3 comments

Hello!

Is there a way to extract the data-frames responsible for the trend, seasonality, and holiday components? I am asking because I'd like to visualize these components separately using another tool.

Thank you

abdelatifsd avatar May 18 '21 17:05 abdelatifsd

Hi! For trend and holidays, it should just be the trend and holidays columns in the forecast dataframe. i.e. if you ran forecast = m.predict(future), the data will be in the columns of the forecast dataframe.

For the seasonal components, you'll have to extract some of the source code into your own function. For example, here is the weekly seasonality plotting logic:

  • Python: https://github.com/facebook/prophet/blob/b75844e07c3b09bf3bc383c9d43241c554dd251b/python/prophet/plot.py#L273-L301
  • R: https://github.com/facebook/prophet/blob/b75844e07c3b09bf3bc383c9d43241c554dd251b/R/R/plot.R#L247-L268

If you return the seas variable from each of those functions, you'll get the dataframe required for plotting.

tcuongd avatar May 19 '21 11:05 tcuongd

Thank you! That's exactly what I was looking for:)

abdelatifsd avatar May 19 '21 17:05 abdelatifsd

Hi @tcuongd , Regarding trend or seasonality, source code focuses on plotting components of forecast data frame. Yet in the guide of Quick Start, plot_component or add_changepoints_to_plot not only shows trend for forecast part, but also shows trend for historical data part. Is there a way to extract fitted value or components of training data set?

Thanks a lot!

daysofcandy avatar Aug 15 '22 07:08 daysofcandy