data.manydataset.ManyToOneDataset(
df_list,
target,
drop=None,
dtype=torch.float32,
)
Sequence dataset with a single target value per sequence.
Like ManyToManyDataset, but item i pairs the full feature sequence with the scalar target taken from the first row of sequence i.
Parameters
| 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
| data |
List[pd.DataFrame] |
DataFrames with the drop columns removed. |
| target |
List[torch.Tensor] |
Per-sequence scalar target tensors. |
| features |
List[torch.Tensor] |
Per-sequence feature tensors, shape (T_i, n_features). |
Examples
import pandas as pd
from spotoptim.data.manydataset import ManyToOneDataset
df1 = pd.DataFrame({"x": [1.0, 2.0, 3.0], "y": [5.0, 5.0, 5.0]})
df2 = pd.DataFrame({"x": [4.0, 5.0], "y": [7.0, 7.0]})
ds = ManyToOneDataset([df1, df2], target="y")
features, target = ds[1]
print(features.shape, target)
torch.Size([2, 1]) tensor(7.)