簡體   English   中英

使用 facebook 先知在具有多個時間序列的數據框中進行時間序列預測

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

我有以下數據框:

             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

我想使用此數據框使用 facebook 的prophet庫進行時間序列預測。 該庫中有沒有辦法使用這個數據框? 棘手的部分是我有多個 fid 值,對於每個 fid,我在via列中有多個日期的數據。 我想via列為 foll 做預測。 數據框:

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

目前, prophet不支持多變量時間序列預測或 VAR。 最好的辦法是在基於fid列拆分數據框后在循環中創建預測。

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
    # ...
})

編輯

沒有注意到這個問題被標記為 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
    # ...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM