Skip to content

Benchmark

Benchmark

A time series forecasting benchmark consisting of multiple Task objects.

Attributes:

Name Type Description
tasks list[Task]

Collection of tasks in the benchmark.

Source code in src/fev/benchmark.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
class Benchmark:
    """A time series forecasting benchmark consisting of multiple [`Task`][fev.Task] objects.

    Attributes
    ----------
    tasks : list[Task]
        Collection of tasks in the benchmark.
    """

    def __init__(self, tasks: list[Task]):
        for t in tasks:
            if not isinstance(t, Task):
                raise ValueError(f"`tasks` must be a list of `Task` objects (got {type(t)})")
        self.tasks: list[Task] = tasks  # declare type explicitly to correctly show up in the docs

    @classmethod
    def from_yaml(cls, file_path: str | Path) -> "Benchmark":
        """Load benchmark definition from a YAML file.

        The YAML file should contain the key `'tasks'` with a list of dictionaries with task definitions.

            tasks:
            - dataset_path: autogluon/chronos_datasets
              dataset_config: m4_hourly
              horizon: 24
              num_windows: 2
            - dataset_path: autogluon/chronos_datasets
              dataset_config: monash_cif_2016
              horizon: 12

        Parameters
        ----------
        file_path : str | Path
            URL or path of a YAML file containing the task definitions.
        """
        try:
            if str(file_path).startswith(("http://", "https://")):
                response = requests.get(file_path)
                response.raise_for_status()
                config = yaml.safe_load(response.text)
            else:
                with open(file_path) as file:
                    config = yaml.safe_load(file)
        except Exception:
            raise ValueError("Failed to load the file")

        return cls.from_list(config["tasks"])

    @classmethod
    def from_list(cls, task_configs: list[dict]) -> "Benchmark":
        """Load benchmark definition from a list of dictionaries.

        Each dictionary must follow the schema compatible with a `fev.task.Task`.
        """
        return cls(tasks=[Task(**conf) for conf in task_configs])

Attributes

tasks: list[Task] = tasks instance-attribute

Functions

from_yaml(file_path: str | Path) -> Benchmark classmethod

Load benchmark definition from a YAML file.

The YAML file should contain the key 'tasks' with a list of dictionaries with task definitions.

tasks:
- dataset_path: autogluon/chronos_datasets
  dataset_config: m4_hourly
  horizon: 24
  num_windows: 2
- dataset_path: autogluon/chronos_datasets
  dataset_config: monash_cif_2016
  horizon: 12

Parameters:

Name Type Description Default
file_path str | Path

URL or path of a YAML file containing the task definitions.

required
Source code in src/fev/benchmark.py
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
@classmethod
def from_yaml(cls, file_path: str | Path) -> "Benchmark":
    """Load benchmark definition from a YAML file.

    The YAML file should contain the key `'tasks'` with a list of dictionaries with task definitions.

        tasks:
        - dataset_path: autogluon/chronos_datasets
          dataset_config: m4_hourly
          horizon: 24
          num_windows: 2
        - dataset_path: autogluon/chronos_datasets
          dataset_config: monash_cif_2016
          horizon: 12

    Parameters
    ----------
    file_path : str | Path
        URL or path of a YAML file containing the task definitions.
    """
    try:
        if str(file_path).startswith(("http://", "https://")):
            response = requests.get(file_path)
            response.raise_for_status()
            config = yaml.safe_load(response.text)
        else:
            with open(file_path) as file:
                config = yaml.safe_load(file)
    except Exception:
        raise ValueError("Failed to load the file")

    return cls.from_list(config["tasks"])

from_list(task_configs: list[dict]) -> Benchmark classmethod

Load benchmark definition from a list of dictionaries.

Each dictionary must follow the schema compatible with a fev.task.Task.

Source code in src/fev/benchmark.py
57
58
59
60
61
62
63
@classmethod
def from_list(cls, task_configs: list[dict]) -> "Benchmark":
    """Load benchmark definition from a list of dictionaries.

    Each dictionary must follow the schema compatible with a `fev.task.Task`.
    """
    return cls(tasks=[Task(**conf) for conf in task_configs])