Skip to main content

module neuralforecast.tsdataset


class TimeSeriesLoader

TimeSeriesLoader DataLoader. Small change to PyTorch’s Data loader. Combines a dataset and a sampler, and provides an iterable over the given dataset. The class ~torch.utils.data.DataLoader supports both map-style and iterable-style datasets with single- or multi-process loading, customizing loading order and optional automatic batching (collation) and memory pinning. Args:
  • dataset: Dataset to load data from.
  • batch_size (int, optional): How many samples per batch to load. Defaults to 1.
  • shuffle (bool, optional): Set to True to have the data reshuffled at every epoch. Defaults to False.
  • sampler (Sampler or Iterable, optional): Defines the strategy to draw samples from the dataset. Can be any Iterable with len implemented. If specified, shuffle must not be specified. Defaults to None.
  • drop_last (bool, optional): Set to True to drop the last incomplete batch. Defaults to False.
  • **kwargs: Additional keyword arguments for DataLoader.

method __init__

__init__(dataset, **kwargs)

property multiprocessing_context


class BaseTimeSeriesDataset

Base class for time series datasets. Args:
  • temporal_cols: Column names for temporal features.
  • max_size (int): Maximum size of time series.
  • min_size (int): Minimum size of time series.
  • y_idx (int): Index of target variable.
  • static (Optional): Static features array.
  • static_cols (Optional): Column names for static features.

method __init__

__init__(
    temporal_cols,
    max_size: int,
    min_size: int,
    y_idx: int,
    static=None,
    static_cols=None
)

class TimeSeriesDataset

Time series dataset implementation. Args:
  • temporal: Temporal data array.
  • temporal_cols: Column names for temporal features.
  • indptr: Index pointers for time series grouping.
  • y_idx (int): Index of target variable.
  • static (Optional): Static features array.
  • static_cols (Optional): Column names for static features.

method __init__

__init__(
    temporal,
    temporal_cols,
    indptr,
    y_idx: int,
    static=None,
    static_cols=None
)

method align

align(
    df: Union[DataFrame, DataFrame],
    id_col: str,
    time_col: str,
    target_col: str
) → TimeSeriesDataset

method append

append(futr_dataset: 'TimeSeriesDataset') → TimeSeriesDataset
Add future observations to the dataset. Args:
  • futr_dataset (TimeSeriesDataset): Future dataset to append.
Returns:
  • TimeSeriesDataset: Copy of dataset with future observations appended.
Raises:
  • ValueError: If datasets have different number of groups.

method from_df

from_df(df, static_df=None, id_col='unique_id', time_col='ds', target_col='y')

method trim_dataset

trim_dataset(dataset, left_trim: int = 0, right_trim: int = 0)
Trim temporal information from a dataset. Returns temporal indexes [t+left:t-right] for all series. Args:
  • dataset: Dataset to trim.
  • left_trim (int, optional): Number of observations to trim from the left. Defaults to 0.
  • right_trim (int, optional): Number of observations to trim from the right. Defaults to 0.
Returns:
  • TimeSeriesDataset: Trimmed dataset.
Raises:
  • Exception: If trim size exceeds minimum series length.

method update_dataset

update_dataset(
    dataset,
    futr_df,
    id_col='unique_id',
    time_col='ds',
    target_col='y'
)

class LocalFilesTimeSeriesDataset

Time series dataset that loads data from local files. Args:
  • files_ds (List[str]): List of file paths.
  • temporal_cols: Column names for temporal features.
  • id_col (str): Name of ID column.
  • time_col (str): Name of time column.
  • target_col (str): Name of target column.
  • last_times: Last time for each time series.
  • indices: Series indices.
  • max_size (int): Maximum size of time series.
  • min_size (int): Minimum size of time series.
  • y_idx (int): Index of target variable.
  • static (Optional): Static features array.
  • static_cols (Optional): Column names for static features.

method __init__

__init__(
    files_ds: List[str],
    temporal_cols,
    id_col: str,
    time_col: str,
    target_col: str,
    last_times,
    indices,
    max_size: int,
    min_size: int,
    y_idx: int,
    static=None,
    static_cols=None
)

method from_data_directories

from_data_directories(
    directories,
    static_df=None,
    exogs=[],
    id_col='unique_id',
    time_col='ds',
    target_col='y'
)
Create dataset from data directories. Expects directories to be a list of directories of the form [unique_id=id_0, unique_id=id_1, …]. Each directory should contain the timeseries corresponding to that unique_id, represented as a pandas or polars DataFrame. The timeseries can be entirely contained in one parquet file or split between multiple, but within each parquet files the timeseries should be sorted by time. Args:
  • directories: List of directory paths.
  • static_df (Optional): Static features DataFrame.
  • exogs (List, optional): List of exogenous variable names. Defaults to [].
  • id_col (str, optional): Name of ID column. Defaults to “unique_id”.
  • time_col (str, optional): Name of time column. Defaults to “ds”.
  • target_col (str, optional): Name of target column. Defaults to “y”.
Returns:
  • LocalFilesTimeSeriesDataset: Dataset created from directories.

class TimeSeriesDataModule

PyTorch Lightning data module for time series datasets. Args:
  • dataset (BaseTimeSeriesDataset): Time series dataset.
  • batch_size (int, optional): Batch size for training. Defaults to 32.
  • valid_batch_size (int, optional): Batch size for validation. Defaults to 1024.
  • drop_last (bool, optional): Whether to drop the last incomplete batch. Defaults to False.
  • shuffle_train (bool, optional): Whether to shuffle training data. Defaults to True.
  • **dataloaders_kwargs: Additional keyword arguments for data loaders.

method __init__

__init__(
    dataset: BaseTimeSeriesDataset,
    batch_size=32,
    valid_batch_size=1024,
    drop_last=False,
    shuffle_train=True,
    **dataloaders_kwargs
)

property hparams

The collection of hyperparameters saved with :meth:save_hyperparameters. It is mutable by the user. For the frozen set of initial hyperparameters, use :attr:hparams_initial. Returns: Mutable hyperparameters dictionary

property hparams_initial

The collection of hyperparameters saved with :meth:save_hyperparameters. These contents are read-only. Manual updates to the saved hyperparameters can instead be performed through :attr:hparams. Returns:
  • AttributeDict: immutable initial hyperparameters

method predict_dataloader

predict_dataloader()

method train_dataloader

train_dataloader()

method val_dataloader

val_dataloader()