imblearn.tensorflow.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 — 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 sample_indices_.

Parameters
Xndarray, shape (n_samples, n_features)

Original imbalanced dataset.

yndarray, shape (n_samples,) or (n_samples, n_classes)

Associated targets.

sample_weightndarray, shape (n_samples,)

Sample weight.

samplerobject or None, optional (default=RandomUnderSampler)

A sampler instance which has an attribute sample_indices_. By default, the sampler used is a imblearn.under_sampling.RandomUnderSampler.

batch_sizeint, optional (default=32)

Number of samples per gradient update.

keep_sparsebool, optional (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 the RandomState instance used by np.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.