unit8co/darts

Gridsearch doesn't work with multiple timeseries

Open

#1,622 建立於 2023年3月5日

在 GitHub 查看
 (3 留言) (0 反應) (0 負責人)Python (6,832 star) (762 fork)batch import
good first issueimprovement

描述

Describe the bug While calling gridsearch for NeuralNets using multiple timeseries, we get an error: ValueError: The two TimeSeries sequences must have the same length. Note that in the example, the 2 timeseries are of the same length.

To Reproduce

import pandas as pd
from darts import TimeSeries
from darts.models import (
    NHiTSModel
)
from darts.metrics import rmse
import numpy as np


data = [['item1',  '01-01-2023', 10],
        ['item1',  '01-02-2023', 20],
        ['item1',  '01-03-2023', 30],
        ['item1',  '01-04-2023', 40],
        ['item1',  '01-05-2023', 50],
        ['item1',  '01-06-2023', 60],
        ['item1',  '01-07-2023', 70],
        ['item1',  '01-08-2023', 80],
        ['item1',  '01-09-2023', 90],
        ['item2',  '01-01-2023', 100],
        ['item2',  '01-02-2023', 200],
        ['item2',  '01-03-2023', 300],
        ['item2',  '01-04-2023', 400],
        ['item2',  '01-05-2023', 500],
        ['item2',  '01-06-2023', 600],
        ['item2',  '01-07-2023', 700],
        ['item2',  '01-08-2023', 800],
        ['item2',  '01-09-2023', 900]
       ]
df = pd.DataFrame(data, columns=['item' , 'sale_date', 'units'])
df['sale_date'] = pd.to_datetime(df['sale_date'])

item_list = TimeSeries.from_group_dataframe(df, group_cols = 'item', value_cols = 'units', time_col = 'sale_date')



params = {
    "input_chunk_length" : [6],
    "output_chunk_length" : [1],
    "num_layers": [1,2,3]


}

res = NHiTSModel.gridsearch(parameters=params,
                            series=item_list,
                            metric=rmse,
                            reduction=np.mean,
                            n_jobs=-1,
                            n_random_samples=0.99,
                            verbose=True,
                            forecast_horizon = 1
                       )

ValueError: The two TimeSeries sequences must have the same length.

Expected behavior The code should do a gridsearch successfully and be able to give us the best model.

System (please complete the following information):

  • Python version: 3.9
  • darts version: 0.23.1

Additional context Gridsearch works with a single timeseries data.

貢獻者指南