BalanceCascadeUnderSampler

class imbalanced_ensemble.sampler.under_sampling.BalanceCascadeUnderSampler(*, sampling_strategy='auto', replacement=False, random_state=None)

Class to perform under-sampling for BalanceCascade in [1].

Parameters
sampling_strategyfloat, str, dict, callable, default=’auto’

Sampling information to sample the data set.

  • When float, it corresponds to the desired ratio of the number of samples in the minority class over the number of samples in the majority class after resampling. Therefore, the ratio is expressed as \(\alpha_{us} = N_{m} / N_{rM}\) where \(N_{m}\) is the number of samples in the minority class and \(N_{rM}\) is the number of samples in the majority class after resampling.

    Warning

    float is only available for binary classification. An error is raised for multi-class classification.

  • When str, specify the class targeted by the resampling. The number of samples in the different classes will be equalized. Possible choices are:

    'majority': resample only the majority class;

    'not minority': resample all classes but the minority class;

    'not majority': resample all classes but the majority class;

    'all': resample all classes;

    'auto': equivalent to 'not minority'.

  • When dict, the keys correspond to the targeted classes. The values correspond to the desired number of samples for each targeted class.

  • When callable, function taking y and returns a dict. The keys correspond to the targeted classes. The values correspond to the desired number of samples for each class.

replacementbool, default=False

Whether samples are drawn with replacement. If False and soft_resample_flag = False, may raise an error when a bin has insufficient number of data samples for resampling.

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.

Attributes
sample_indices_ndarray of shape (n_new_samples,)

Indices of the samples selected.

See also

SelfPacedUnderSampler

Dynamic under-sampling for SelfPacedEnsemble.

Notes

Supports multi-class resampling by sampling each class independently. Supports heterogeneous data as object array containing string and numeric data.

References

1

Liu, X. Y., Wu, J., & Zhou, Z. H. “Exploratory undersampling for class-imbalance learning.” IEEE Transactions on Systems, Man, and Cybernetics, Part B (Cybernetics) 39.2 (2008): 539-550.

Methods

fit(X, y)

Check inputs and statistics of the sampler.

fit_resample(X, y, *, sample_weight, **kwargs)

Resample the dataset.

get_params([deep])

Get parameters for this estimator.

set_params(**params)

Set the parameters of this estimator.

fit(X, y)

Check inputs and statistics of the sampler.

You should use fit_resample in all cases.

Parameters
X{array-like, dataframe, sparse matrix} of shape (n_samples, n_features)

Data array.

yarray-like of shape (n_samples,)

Target array.

Returns
selfobject

Return the instance itself.

fit_resample(X, y, *, sample_weight, **kwargs)

Resample the dataset.

Parameters
X{array-like, dataframe, sparse matrix} of shape (n_samples, n_features)

Matrix containing the data which have to be sampled.

yarray-like of shape (n_samples,)

Corresponding label for each sample in X.

y_pred_probaarray-like of shape (n_samples, n_classes)

The predicted class probabilities of the input samples by the current SPE ensemble classifier. The order of the classes corresponds to that in the parameter classes_.

dropped_indexarray-like of shape (n_samples,)

The mask corresponding to X, True indicates that the corresponding sample is already discarded.

keep_populationsdict

Specify how many samples will be kept for each class after this resampling. The keys (int) correspond to the targeted classes. The values (int) correspond to the number of samples to keep.

classes_ndarray of shape (n_classes,)

The classes labels.

sample_weightarray-like of shape (n_samples,), default=None

Corresponding weight for each sample in X.

Returns
X_resampled{array-like, dataframe, sparse matrix} of shape (n_samples_new, n_features)

The array containing the resampled data.

y_resampledarray-like of shape (n_samples_new,)

The corresponding label of X_resampled.

sample_weightarray-like of shape (n_samples_new,), default=None

The corresponding weight of X_resampled. Only will be returned if input sample_weight is not None.

get_params(deep=True)

Get parameters for this estimator.

Parameters
deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns
paramsdict

Parameter names mapped to their values.

set_params(**params)

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Parameters
**paramsdict

Estimator parameters.

Returns
selfestimator instance

Estimator instance.