简体   繁体   中英

Using facebook prophet to do time-series forecasting in dataframe that has multiple time-series

I have the following dataframe:

             fid         via
2015-01-18  id_22207  0.275056
2015-01-30  id_22207  0.306961
2015-02-23  id_22207  0.285065
2015-02-24  id_22207  0.337570
2015-02-27  id_22207  0.311612
2015-01-18  id_22208  0.371765
2015-01-20  id_22208  0.405391
2015-02-11  id_22208  0.354052
2015-02-24  id_22208  0.421126
2015-03-15  id_22208  0.454406

I want to use this dataframe to do time-series forecasting using facebook's prophet library. Is there a way in that library to use this dataframe? The tricky part is that I have multiple fid values, and for each fid I have data in the via column for multiple dates. I want to do forecasting for via column for the foll. dataframe:

2015-03-18  id_22209
2015-03-20  id_22209
2015-03-21  id_22209
2015-03-24  id_22209
2015-03-25  id_22209

Currently, prophet does not support multivariate time-series forecasting or VAR. Your best bet is to create forecasts in a loop after splitting the data frame based on the fid column.

library(tidyverse)
library(prophet)

lapply(split(df, f= df$fid), function(x) {
    # Prophet expects columns to be ds, y
    x <- x %>% rename(y = via, ds = date)

    # Create prophet forecasts
    # ...
})

EDIT

Didn't notice this question was tagged as Python.

unique_fid = df['fid'].unique()
for fid in unique_fid:
    temp_df = df.loc[df['fid'] == fid,['date', 'via']]
    # Prophet expects ds and y as columns
    temp_df.columns = ['ds', 'y']
    # Create prophet forecasts
    # ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM