# SelfPacedUnderSampler

class imbalanced_ensemble.sampler.under_sampling.SelfPacedUnderSampler(*, sampling_strategy='auto', k_bins=5, soft_resample_flag=True, replacement=False, random_state=None)

Class to perform self-paced under-sampling 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.

k_binsint, default=5

The number of hardness bins that were used to approximate hardness distribution. It is recommended to set it to 5. One can try a larger value when the smallest class in the data set has a sufficient number (say, > 1000) of samples.

soft_resample_flagbool, default=False

Whether to use weighted sampling to perform soft self-paced under-sampling, rather than explicitly cut samples into k-bins and perform hard sampling.

replacementbool, default=True

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.

BalanceCascadeUnderSampler

Dynamic under-sampling for BalanceCascade.

Notes

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

References

1

Liu, Z., Cao, W., Gao, Z., Bian, J., Chen, H., Chang, Y., & Liu, T. Y. “Self-paced ensemble for highly imbalanced massive data classification.” 2020 IEEE 36th International Conference on Data Engineering (ICDE). IEEE, 2010: 841-852.

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_.

alphafloat

The self-paced factor that controls SPE under-sampling.

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.