Geometric smote
Class to perform over-sampling using Geometric SMOTE.
GeometricSMOTE(sampling_strategy='auto', k_neighbors=5, truncation_factor=1.0, deformation_factor=0.0, selection_strategy='combined', categorical_features=None, random_state=None)
Bases: BaseOverSampler
Class to to perform over-sampling using Geometric SMOTE.
This algorithm is an implementation of Geometric SMOTE, a geometrically enhanced drop-in replacement for SMOTE. Read more in the [user_guide].
Parameters:
Name | Type | Description | Default |
---|---|---|---|
categorical_features
|
ArrayLike | None
|
Specified which features are categorical. Can either be:
|
None
|
sampling_strategy
|
dict[int, int] | str | float | Callable
|
Sampling information to resample the data set.
|
'auto'
|
random_state
|
RandomState | int | None
|
Control the randomization of the algorithm.
|
None
|
truncation_factor
|
float
|
The type of truncation. The values should be in the [-1.0, 1.0] range. |
1.0
|
deformation_factor
|
float
|
The type of geometry. The values should be in the [0.0, 1.0] range. |
0.0
|
selection_strategy
|
str
|
The type of Geometric SMOTE algorithm with the following options:
|
'combined'
|
k_neighbors
|
NearestNeighbors | int
|
If |
5
|
Attributes:
Name | Type | Description |
---|---|---|
n_features_in_ |
int Number of features in the input dataset. |
|
nns_pos_ |
estimator object
Validated k-nearest neighbours created from the |
|
nn_neg_ |
estimator object
Validated k-nearest neighbours created from the |
|
random_state_ |
RandomState
|
An instance of |
sampling_strategy_ |
dict[int, int]
|
Actual sampling strategy. |
Examples:
>>> import numpy as np
>>> from collections import Counter
>>> from sklearn.datasets import make_classification
>>> from imblearn_extra.gsmote import GeometricSMOTE
>>> np.set_printoptions(legacy='1.25')
>>> X, y = make_classification(n_classes=2, class_sep=2,
... weights=[0.1, 0.9], n_informative=3, n_redundant=1, flip_y=0,
... n_features=20, n_clusters_per_class=1, n_samples=1000, random_state=10)
>>> print('Original dataset shape %s' % Counter(y))
Original dataset shape Counter({{1: 900, 0: 100}})
>>> gsmote = GeometricSMOTE(random_state=1)
>>> X_resampled, y_resampled = gsmote.fit_resample(X, y)
>>> print('Resampled dataset shape %s' % Counter(y_resampled))
Resampled dataset shape Counter({{0: 900, 1: 900}})
Source code in src/imblearn_extra/gsmote/geometric_smote.py
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
|
_check_X_y(X, y)
Check input and output data.
Source code in src/imblearn_extra/gsmote/geometric_smote.py
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 |
|
_decode_categorical(X_init, X_resampled)
Reverses the encoding of the categorical features.
Source code in src/imblearn_extra/gsmote/geometric_smote.py
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 |
|
_encode_categorical(X, y)
Encode categorical features.
Source code in src/imblearn_extra/gsmote/geometric_smote.py
456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 |
|
_make_geometric_samples(X_init, X, y, pos_class_label, n_samples)
A support function that returns artificials samples.
Source code in src/imblearn_extra/gsmote/geometric_smote.py
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 |
|
_populate_categorical_features(X_new, y_new, all_neighbors)
A support function that populates categorical features.
Source code in src/imblearn_extra/gsmote/geometric_smote.py
435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 |
|
_validate_categorical_features()
Validate categorical features.
Source code in src/imblearn_extra/gsmote/geometric_smote.py
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 |
|
_validate_estimators(X)
Validate nearest neighbors estimators.
Source code in src/imblearn_extra/gsmote/geometric_smote.py
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 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
|
make_geometric_sample(center, surface_point, truncation_factor, deformation_factor, random_state)
A support function that returns an artificial point.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
center
|
NDArray
|
The center point. |
required |
surface_point
|
NDArray
|
The point on the surface of the hypersphere. |
required |
truncation_factor
|
float
|
The truncation factor of the algorithm. |
required |
deformation_factor
|
float
|
The defirmation factor of the algorithm. |
required |
random_state
|
RandomState
|
The random state of the process. |
required |
Returns:
Name | Type | Description |
---|---|---|
geometric_sample |
NDArray
|
The generated geometric sample. |
Source code in src/imblearn_extra/gsmote/geometric_smote.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
|
populate_categorical_features(X_new, neighbors, categories_size, random_state)
A support function that populates categorical features.
Source code in src/imblearn_extra/gsmote/geometric_smote.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
|