data.manydataset.ManyToManyDataset

data.manydataset.ManyToManyDataset(
    df_list,
    target,
    drop=None,
    dtype=torch.float32,
)

Sequence dataset with one target value per time step.

Each element of df_list is one variable-length sequence; item i is the pair (features_i, targets_i) with shapes (T_i, n_features) and (T_i,).

Parameters

Name Type Description Default
df_list List[pd.DataFrame] List of pandas DataFrames, one per sequence. required
target str The target column name. required
drop Optional[Union[str, List[str]]] Column(s) to drop from the DataFrames before extracting features. If a listed column is missing, no column is dropped. Defaults to None. None
dtype torch.dtype Data type for the tensors. Defaults to torch.float32. torch.float32

Attributes

Name Type Description
data List[pd.DataFrame] DataFrames with the drop columns removed.
target List[torch.Tensor] Per-sequence target tensors, shape (T_i,).
features List[torch.Tensor] Per-sequence feature tensors, shape (T_i, n_features).

Examples

import pandas as pd
from spotoptim.data.manydataset import ManyToManyDataset

df1 = pd.DataFrame({"x": [1.0, 2.0, 3.0], "y": [2.0, 4.0, 6.0]})
df2 = pd.DataFrame({"x": [4.0, 5.0], "y": [8.0, 10.0]})
ds = ManyToManyDataset([df1, df2], target="y")
print(len(ds))
features, targets = ds[0]
print(features.shape, targets.shape)
2
torch.Size([3, 1]) torch.Size([3])