dataset
sorix.utils.data.dataset ¶
Dataset ¶
Base class for all datasets in Sorix.
Inspired by PyTorch's Dataset API, it provides a standard way to wrap data and apply transformations during retrieval.
Parameters:
-
X(Any) –Feature data (NumPy array, list, etc.).
-
y(Any, default:None) –Target data (optional).
-
transform(Optional[Callable], default:None) –A function/transform that takes in a sample and returns a transformed version.
-
target_transform(Optional[Callable], default:None) –A function/transform that takes in the target and transforms it.
Source code in sorix/utils/data/dataset.py
WalkForwardSplit ¶
Chronological (walk-forward) cross-validation splitter.
Unlike random k-fold, this splitter respects temporal order: the training window always precedes the validation window, preventing future data leakage. Use this for time-series datasets such as match histories or financial data.
There are two modes:
- Expanding window (default): the training set grows with each fold — all data before the validation window is used.
- Rolling window (
expanding=False): the training set is a fixed-size sliding window of the lasttrain_sizesamples.
Because train_size only means something for a rolling window, passing it
selects rolling mode automatically. Passing both train_size and an
explicit expanding=True is contradictory and raises ValueError.
Parameters:
-
n_splits(int, default:5) –Number of splits. Default: 5.
-
train_size(int | None, default:None) –Size of the rolling training window. Passing it switches to rolling mode.
Nonekeeps the expanding window, which uses all data before the validation window. Default:None. -
val_size(int | None, default:None) –Number of validation samples per split.
Noneauto-computeslen(X) // (n_splits + 1). Default:None. -
gap(int, default:0) –Number of samples to drop between the training and validation windows (e.g. to simulate a prediction lag). Default: 0.
-
expanding(bool | None, default:None) –Window mode.
None(default) infers it fromtrain_size. PassFalsefor a rolling window,Trueto force an expanding one.
Raises:
-
ValueError–If
train_sizeis combined withexpanding=True, or if any size argument is out of range.
Note
split() yields slices of the data, not index arrays as
scikit-learn's TimeSeriesSplit does. With a pandas object, pass
df.to_numpy() or slice with .iloc yourself.
Example::
splitter = WalkForwardSplit(n_splits=5, val_size=50, gap=1)
for train_X, train_y, val_X, val_y in splitter.split(X, y):
model.fit(train_X, train_y)
preds = model.predict(val_X)
Source code in sorix/utils/data/dataset.py
split ¶
Generate chronological train/validation splits.
Always yields exactly n_splits folds; if the data is too short to fit
them all, it raises instead of silently returning fewer.
Parameters:
-
X(Any) –Feature array with shape
(n_samples, ...). -
y(Optional[Any], default:None) –Target array with shape
(n_samples,). Optional.
Yields:
-
Tuple[Any, ...]–Tuple[Any, ...]:
(train_X, train_y, val_X, val_y)ifyis provided, otherwise(train_X, val_X).
Raises:
-
ValueError–If
yis shorter thanX, or iflen(X)cannot accommodaten_splitsfolds ofval_sizesamples plusgapand at least one training sample.