balanced_batch_generator(X, y, *, sample_weight=None, sampler=None, batch_size=32, keep_sparse=False, random_state=None)¶
Create a balanced batch generator to train tensorflow model.
Returns a generator — as well as the number of step per epoch — which is given to
fit_generator. The sampler defines the sampling strategy used to balance the dataset ahead of creating the batch. The sampler should have an attribute
New in version 0.4.
- Xndarray of shape (n_samples, n_features)
Original imbalanced dataset.
- yndarray of shape (n_samples,) or (n_samples, n_classes)
- sample_weightndarray of shape (n_samples,), default=None
- samplersampler object, default=None
A sampler instance which has an attribute
sample_indices_. By default, the sampler used is a
- batch_sizeint, default=32
Number of samples per gradient update.
- keep_sparsebool, default=False
Either or not to conserve or not the sparsity of the input
X. By default, the returned batches will be dense.
- random_stateint, RandomState instance, default=None
Control the randomization of the algorithm.
random_stateis the seed used by the random number generator;
RandomStateinstance, random_state is the random number generator;
None, the random number generator is the
RandomStateinstance used by
- generatorgenerator of tuple
Generate batch of data. The tuple generated are either (X_batch, y_batch) or (X_batch, y_batch, sampler_weight_batch).
The number of samples per epoch.