balanced_batch_generator#
- imblearn.tensorflow.balanced_batch_generator(X, y, *, sample_weight=None, sampler=None, batch_size=32, keep_sparse=False, random_state=None)[source]#
Create a balanced batch generator to train tensorflow model.
Returns a generator — as well as the number of step per epoch — to iterate to get the mini-batches. The sampler defines the sampling strategy used to balance the dataset ahead of creating the batch. The sampler should have an attribute
sample_indices_
.Added in version 0.4.
- Parameters:
- Xndarray of shape (n_samples, n_features)
Original imbalanced dataset.
- yndarray of shape (n_samples,) or (n_samples, n_classes)
Associated targets.
- sample_weightndarray of shape (n_samples,), default=None
Sample weight.
- samplersampler object, default=None
A sampler instance which has an attribute
sample_indices_
. By default, the sampler used is aRandomUnderSampler
.- 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.
If int,
random_state
is the seed used by the random number generator;If
RandomState
instance, random_state is the random number generator;If
None
, the random number generator is theRandomState
instance used bynp.random
.
- Returns:
- generatorgenerator of tuple
Generate batch of data. The tuple generated are either (X_batch, y_batch) or (X_batch, y_batch, sampler_weight_batch).
- steps_per_epochint
The number of samples per epoch.