Distribution
Distributor classes for clustering-based oversampling.
DensityDistributor(filtering_threshold='auto', distances_exponent='auto', sparsity_based=True, distribution_ratio=1.0)
Bases: BaseDistributor
Class to perform density based distribution.
Samples are distributed based on the density of clusters.
Read more in the [user_guide].
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filtering_threshold
|
float | str
|
The threshold of a filtered cluster. It can be any non-negative number or
|
'auto'
|
distances_exponent
|
float | str
|
The exponent of the mean distance in the density calculation. It can be
any non-negative number or
|
'auto'
|
sparsity_based
|
bool
|
Whether sparse clusters receive more generated samples.
|
True
|
distribution_ratio
|
float
|
The ratio of intra-cluster to inter-cluster generated samples. It is a
number in the |
1.0
|
Attributes:
Name | Type | Description |
---|---|---|
clusters_density_ |
Density
|
Each dict key is a multi-label tuple of shape |
distances_exponent_ |
float
|
Actual exponent of the mean distance used in the calculations. |
distribution_ratio_ |
float
|
A copy of the parameter in the constructor. |
filtered_clusters_ |
List[MultiLabel]
|
Each element is a tuple of |
filtering_threshold_ |
float
|
Actual filtering threshold used in the calculations. |
inter_distribution_ |
InterDistribution
|
Each dict key is a multi-label tuple of
shape |
intra_distribution_ |
IntraDistribution
|
Each dict key is a multi-label tuple of shape |
labels_ |
Labels
|
Labels of each sample. |
neighbors_ |
Neighbors
|
An array that contains all neighboring pairs. Each row is a unique neighboring pair. |
majority_class_label_ |
int
|
The majority class label. |
n_samples_ |
int
|
The number of samples. |
sparsity_based_ |
bool
|
A copy of the parameter in the constructor. |
unique_class_labels_ |
Labels
|
An array of unique class labels. |
unique_cluster_labels_ |
Labels
|
An array of unique cluster labels. |
Examples:
>>> import numpy as np
>>> from imblearn_extra.clover.distribution import DensityDistributor
>>> from sklearn.datasets import load_iris
>>> from sklearn.cluster import KMeans
>>> from imblearn.datasets import make_imbalance
>>> np.set_printoptions(legacy='1.25')
>>> X, y = make_imbalance(
... *load_iris(return_X_y=True),
... sampling_strategy={0:50, 1:40, 2:30},
... random_state=0
... )
>>> labels = KMeans(random_state=0, n_init='auto').fit_predict(X, y)
>>> density_distributor = DensityDistributor().fit(X, y, labels)
>>> density_distributor.filtered_clusters_
[(6, 1), (0, 1), (3, 1), (7, 1), (5, 2), (2, 2), (3, 2), (6, 2), (0, 2)]
>>> density_distributor.intra_distribution_
{(6, 1): 0.50604609281055... (0, 1): 0.143311766542168...}
>>> density_distributor.inter_distribution_
{}
Source code in src/imblearn_extra/clover/distribution/_density.py
142 143 144 145 146 147 148 149 150 151 152 |
|
_calculate_clusters_density(X, y)
Calculate the density of the filtered clusters.
Source code in src/imblearn_extra/clover/distribution/_density.py
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
|
_check_parameters(X, y, neighbors)
Check distributor parameters.
Source code in src/imblearn_extra/clover/distribution/_density.py
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
|
_identify_filtered_clusters(y)
Identify the filtered clusters.
Source code in src/imblearn_extra/clover/distribution/_density.py
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
|
_inter_distribute(X, y, labels, neighbors)
Between the clusters distribution.
Distribute the generated samples between clusters based on their density.
Source code in src/imblearn_extra/clover/distribution/_density.py
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 |
|
_intra_distribute(X, y, labels, neighbors)
In the clusters distribution.
Distribute the generated samples in each cluster based on their density.
Source code in src/imblearn_extra/clover/distribution/_density.py
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 |
|