【问题标题】:splitting the training data based on date column根据日期列拆分训练数据
【发布时间】:2022-10-18 22:39:10
【问题描述】:

我有每周的时间序列数据,我想在上面测试多个时间序列。

原始数据看起来像

date    visits
1/22/2021   796105
1/29/2021   742833
2/5/2021    918413
2/12/2021   806033
.
.
.
9/23/2022   3610023
9/30/2022   2833338

我想将训练数据拆分为多个数据框并始终预测接下来的 12 周

例如 :

train_1 = data until 15-jan-2022
test_1 = next 12 weeks

train_2 = data until 15-feb-2022
test_2 = next 12 weeks
.
.
train_x = data until 15-jul-2022
test_x = next 12 weeks

稍后我想为我的 holt Winter 预测算法创建一个 for 循环。我看了https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.TimeSeriesSplit.html 但无法理解我的数据集

有人可以帮忙吗?先感谢您! .

【问题讨论】:

    标签: python time-series facebook-prophet train-test-split holtwinters


    【解决方案1】:

    根据范围,我们可以设置如下: -

    train_and_test = []
    train_and_test.append((df.iloc[:52, 0], df.iloc[52:62, 0]))
    train_and_test.append((df.iloc[:56, 0], df.iloc[56:66, 0]))
    train_and_test.append((df.iloc[:60, 0], df.iloc[60:70, 0]))
    train_and_test.append((df.iloc[:65, 0], df.iloc[65:75, 0]))
    train_and_test.append((df.iloc[:69, 0], df.iloc[69:79, 0]))
    train_and_test.append((df.iloc[:73, 0], df.iloc[73:83, 0]))
    train_and_test.append((df.iloc[:78, 0], df.iloc[78:88, 0]))
    train_and_test.append((df.iloc[:82, 0], df.iloc[82:90, 0]))
    
    for train_df ,test_df in train_and_test:
      .....
    
    

    【讨论】:

      猜你喜欢
      • 2020-09-12
      • 2019-09-11
      • 1970-01-01
      • 2019-12-09
      • 2018-02-24
      • 1970-01-01
      • 1970-01-01
      • 2021-12-08
      • 2017-12-25
      相关资源
      最近更新 更多