Random oversampling methods for imbalanced learning.
Simple oversampling techniques that duplicate minority samples.
Classes
Random over-sampling by duplicating minority samples.
Simply duplicates random minority class samples to balance classes.
Constructor
__init__( self, sampling_strategy: Union[float, str, dict] = 'auto', random_state: Optional[int] = None, shrinkage: Optional[float] = None, )
Parameters
sampling_strategy
float or str or dict
= 'auto'
Sampling strategy:
- •'auto': balance all classes to match majority
- •'minority': only oversample minority class
- •dict: {class_label: target_count}
random_state
int
Random seed.
shrinkage
float
If not None, adds Gaussian noise with this shrinkage factor.
python
>>> from tuiml.preprocessing.sampling import RandomOverSampler
>>> ros = RandomOverSampler(sampling_strategy='auto')
>>> X_res, y_res = ros.fit_resample(X, y)
Methods
transform
(self, X: np.ndarray) -> np.ndarray
__repr__
(self) -> str
Cluster-based oversampling.
Clusters each class and oversamples within clusters to preserve data distribution.
Constructor
__init__( self, sampling_strategy: Union[float, str, dict] = 'auto', n_clusters: int = 5, random_state: Optional[int] = None, )
Parameters
sampling_strategy
str or dict
= 'auto'
Sampling strategy.
n_clusters
int
= 5
Number of clusters per class.
random_state
int
Random seed.
python
>>> from tuiml.preprocessing.sampling import ClusterOverSampler
>>> cbos = ClusterOverSampler(n_clusters=3)
>>> X_res, y_res = cbos.fit_resample(X, y)
Methods
transform
(self, X: np.ndarray) -> np.ndarray
__repr__
(self) -> str