pytensor_ml.util.DataLoader#
- class pytensor_ml.util.DataLoader(X, y, batch_size=64, dtype=None, random_state=None)#
Draw shuffled, fixed-size batches from a dataset, cycling indefinitely.
Calling the loader returns the next
(X_batch, y_batch). Batches are alwaysbatch_sizerows: a pass that runs off the end of the data is topped up from a freshly shuffled order rather than coming up short, so a batch may straddle two epochs.- Parameters:
- X
ndarray Features, indexed along the first axis.
- y
ndarray Targets, indexed along the first axis and aligned row-wise with
X.- batch_size
int Rows per batch. Default 64.
- dtype
str, optional Dtype to cast
Xandyto. Defaults tofloatX.- random_state
intornumpyGenerator, optional Seed for the shuffling generator, for reproducible batch sequences.
- X
Examples
Call the loader once per training step; it reshuffles and wraps around on its own, so the loop never has to track epoch boundaries:
import numpy as np from pytensor_ml.util import DataLoader X = np.random.default_rng(0).normal(size=(500, 8)) y = np.random.default_rng(1).normal(size=(500, 1)) loader = DataLoader(X, y, batch_size=32, random_state=0) X_batch, y_batch = loader()
Methods
DataLoader.__init__(X, y[, batch_size, ...])