Task
Task
A univariate or multivariate time series forecasting task.
A Task
stores all information uniquely identifying the task, such as path to the dataset, forecast horizon,
evaluation metric and names of the target & covariate columns.
This object handles dataset loading, train/test splitting, and prediction evaluation for time series forecasting tasks.
A single Task
consists of one or more EvaluationWindow
objects that can be
accessed using iter_windows()
or get_window()
methods.
After making predictions for each evaluation window, you can evaluate their accuracy using evaluation_summary()
.
Typical workflow:
task = fev.Task(dataset_path="...", num_windows=3, horizon=24)
predictions_per_window = []
for window in task.iter_windows():
past_data, future_data = window.get_input_data()
predictions = model.predict(past_data, future_data)
predictions_per_window.append(predictions)
summary = task.evaluation_summary(predictions_per_window, model_name="my_model")
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset_path
|
str
|
Path to the time series dataset stored locally, on S3, or on Hugging Face Hub. See the Examples section below for information on how to load datasets from different sources. |
required |
dataset_config
|
str | None
|
Name of the configuration used when loading datasets from Hugging Face Hub. If |
None
|
horizon
|
int
|
Length of the forecast horizon (in time steps). |
1
|
num_windows
|
int
|
Number of rolling evaluation windows included in the task. |
1
|
initial_cutoff
|
int | str | None
|
Starting position for the first evaluation window that separates past from future data. Can be specified as:
If Note: Time series that are too short for any evaluation window (i.e., have fewer than |
None
|
window_step_size
|
int | str | None
|
Step size between consecutive evaluation windows. Must be an integer if |
horizon
|
min_context_length
|
int
|
Time series with fewer than |
1
|
max_context_length
|
int | None
|
If provided, the past time series will be shortened to at most this many observations. |
None
|
seasonality
|
int
|
Seasonal period of the dataset (e.g., 24 for hourly data, 12 for monthly data). This parameter is used when computing metrics like Mean Absolute Scaled Error (MASE). |
1
|
eval_metric
|
str | dict[str, Any]
|
Evaluation metric used for ultimate evaluation on the test set. Can be specified as either a single string
with the metric's name or a dictionary containing a "name" key and extra hyperparameters for the metric.
For example, MASE can also be specified as |
'MASE'
|
extra_metrics
|
list[str] | list[dict[str, Any]]
|
Additional metrics to be included in the results. Can be specified as a list of strings with the metric's
name or a list of dictionaries. See documentation for |
[]
|
quantile_levels
|
list[float]
|
Quantiles that must be predicted. List of floats between 0 and 1 (for example, |
[]
|
id_column
|
str
|
Name of the column with the unique identifier of each time series.
This column will be casted to |
'id'
|
timestamp_column
|
str
|
Name of the column with the timestamps of the observations. |
'timestamp'
|
target
|
str | list[str]
|
Name of the column that must be predicted. If a string is provided, a univariate forecasting task is created. If a list of strings is provided, a multivariate forecasting task is created. |
'target'
|
generate_univariate_targets_from
|
list[str] | Literal['__ALL__'] | None
|
If provided, a separate univariate time series will be created from each of the
If set to For example, if |
None
|
past_dynamic_columns
|
list[str]
|
Names of covariate columns that are known only in the past. These will be available in the past data, but not in the future data. An error will be raised if these columns are missing from the dataset. |
[]
|
known_dynamic_columns
|
list[str]
|
Names of covariate columns that are known in both past and future. These will be available in past data and future data. An error will be raised if these columns are missing from the dataset. |
[]
|
static_columns
|
list[str]
|
Names of columns containing static covariates that don't change over time. An error will be raised if these columns are missing from the dataset. |
[]
|
task_name
|
str | None
|
Human-readable name for the task. Defaults to This field is only here for convenience and is not used for any validation when computing the results. |
None
|
Examples:
Dataset stored on the Hugging Face Hub
>>> Task(dataset_path="autogluon/chronos_datasets", dataset_config="m4_hourly", ...)
Dataset stored as a parquet file (local or S3)
>>> Task(dataset_path="s3://my-bucket/m4_hourly/data.parquet", ...)
Dataset consisting of multiple parquet files (local or S3)
>>> Task(dataset_path="s3://my-bucket/m4_hourly/*.parquet", ...)
Source code in src/fev/task.py
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 |
|
Attributes
predictions_schema: datasets.Features
property
Describes the format that the predictions must follow.
Forecast must always include the key "predictions"
corresponding to the point forecast.
The predictions must also include a key for each of the quantile_levels
.
For example, if quantile_levels = [0.1, 0.9]
, then keys "0.1"
and "0.9"
must be included in the forecast.
freq: str
property
Pandas string corresponding to the frequency of the time series in the dataset.
See pandas documentation for the list of possible values.
This attribute is available after the dataset is loaded with load_full_dataset
, iter_windows
or get_window
.
cutoffs: list[int] | list[str]
property
Cutoffs corresponding to each EvaluationWindow
in the task.
Computed based on num_windows
, initial_cutoff
and window_step_size
attributes of the task.
target_columns: list[str]
property
A list including names of all target columns for this task.
Unlike task.target
that can be a string or a list, task.target_columns
is always a list of strings.
is_multivariate: bool
property
Returns True
if task.target
is a list
, False
otherwise.
dynamic_columns: list[str]
property
List of dynamic covariates available in the task. Does not include the target columns.
Functions
get_window(window_idx: int, storage_options: dict | None = None, trust_remote_code: bool | None = None, num_proc: int = DEFAULT_NUM_PROC) -> EvaluationWindow
Get a single evaluation window by index.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
window_idx
|
int
|
Index of the evaluation window in [0, 1, ..., num_windows - 1]. |
required |
storage_options
|
dict
|
Passed to |
None
|
trust_remote_code
|
bool
|
Passed to |
None
|
num_proc
|
int
|
Number of processes to use for dataset preprocessing. |
DEFAULT_NUM_PROC
|
Returns:
Type | Description |
---|---|
EvaluationWindow
|
A single evaluation window at a specific cutoff containing the data needed to make and evaluate forecasts. |
Source code in src/fev/task.py
550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 |
|
iter_windows(storage_options: dict | None = None, trust_remote_code: bool | None = None, num_proc: int = DEFAULT_NUM_PROC) -> Iterable[EvaluationWindow]
Iterate over the rolling evaluation windows in the task.
Each window contains train/test splits at different cutoff points for time series cross-validation. Use this method for model evaluation and benchmarking.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
storage_options
|
dict
|
Passed to |
None
|
trust_remote_code
|
bool
|
Passed to |
None
|
num_proc
|
int
|
Number of processes to use for dataset preprocessing. |
DEFAULT_NUM_PROC
|
Yields:
Type | Description |
---|---|
EvaluationWindow
|
A single evaluation window at a specific cutoff containing the data needed to make and evaluate forecasts. |
Examples:
>>> for window in task.iter_windows():
... past_data, future_data = window.get_input_data()
... # Make predictions using past_data and future_data
Source code in src/fev/task.py
514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 |
|
evaluation_summary(predictions_per_window: Iterable[datasets.Dataset | list[dict] | datasets.DatasetDict | dict[str, list[dict]]], model_name: str, training_time_s: float | None = None, inference_time_s: float | None = None, trained_on_this_dataset: bool = False, extra_info: dict | None = None) -> dict[str, Any]
Get a summary of the model performance for the given forecasting task.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
predictions_per_window
|
Iterable[Dataset | list[dict] | DatasetDict | dict[str, list[dict]]]
|
Predictions generated by the model for each evaluation window in the task. The length of The predictions for each window must be formatted as described in clean_and_validate_predictions. |
required |
model_name
|
str
|
Name of the model that generated the predictions. |
required |
training_time_s
|
float | None
|
Training time of the model for this task (in seconds). |
None
|
inference_time_s
|
float | None
|
Total inference time to generate all predictions (in seconds). |
None
|
trained_on_this_dataset
|
bool
|
Was the model trained on the dataset associated with this task? Set to False if the model is used in zero-shot mode. |
False
|
extra_info
|
dict | None
|
Optional dictionary with additional information that will be appended to the evaluation summary. |
None
|
Returns:
Name | Type | Description |
---|---|---|
summary |
dict
|
Dictionary that summarizes the model performance on this task. Includes following keys:
|
Source code in src/fev/task.py
832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 |
|
clean_and_validate_predictions(predictions: datasets.DatasetDict | dict[str, list[dict]] | datasets.Dataset | list[dict]) -> datasets.DatasetDict
Convert predictions for a single window into the format needed for computing the metrics.
The following formats are supported for both multivariate and univariate tasks:
DatasetDict
: Must contain a single key for each target intask.target_columns
. Each value in the dict must be adatasets.Dataset
with schema compatible withtask.predictions_schema
. This is the recommended format for providing predictions.dict[str, list[dict]]
: A dictionary with one key for each target intask.target_columns
. Each value in the dict must be a list of dictionaries, each dict following the schema intask.predictions_schema
.
Additionally for univariate tasks, the following formats are supported:
datasets.Dataset
: A singledatasets.Dataset
with schema compatible withtask.predictions_schema
.list[dict]
: A list of dictionaries, where each dict follows the schema intask.predictions_schema
.
Returns:
Name | Type | Description |
---|---|---|
predictions |
DatasetDict
|
A |
Source code in src/fev/task.py
767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 |
|
load_full_dataset(storage_options: dict | None = None, trust_remote_code: bool | None = None, num_proc: int = DEFAULT_NUM_PROC) -> datasets.Dataset
Load the full raw dataset with preprocessing applied.
This method validates the data, loads and preprocesses the dataset according to the task configuration,
including generating univariate targets if generate_univariate_targets_from
is provided.
Note: This method is only provided for information and debugging purposes. For model evaluation, use
iter_windows()
instead to get properly split train/test data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
storage_options
|
dict
|
Passed to |
None
|
trust_remote_code
|
bool
|
Passed to |
None
|
num_proc
|
int
|
Number of processes to use for dataset preprocessing. |
DEFAULT_NUM_PROC
|
Returns:
Type | Description |
---|---|
Dataset
|
The preprocessed dataset with all time series. |
Source code in src/fev/task.py
480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 |
|
to_dict() -> dict
Convert task definition to a dictionary.
Source code in src/fev/task.py
476 477 478 |
|