Skip to content

Commit 54a7b5b

Browse files
authored
MAINT add support for feature_names_in_ (#959)
1 parent ad71707 commit 54a7b5b

21 files changed

+436
-3
lines changed

doc/whats_new/v0.10.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ Compatibility
2222
- Add support for automatic parameters validation as in scikit-learn >= 1.2.
2323
:pr:`955` by :user:`Guillaume Lemaitre <glemaitre>`.
2424

25+
- Add support for `feature_names_in_` as well as `get_feature_names_out` for
26+
all samplers.
27+
:pr:`959` by :user:`Guillaume Lemaitre <glemaitre>`.
28+
2529
Deprecation
2630
...........
2731

imblearn/base.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88

99
import numpy as np
1010
from sklearn.base import BaseEstimator
11+
12+
try:
13+
# scikit-learn >= 1.2
14+
from sklearn.base import OneToOneFeatureMixin
15+
except ImportError:
16+
from sklearn.base import _OneToOneFeatureMixin as OneToOneFeatureMixin
1117
from sklearn.preprocessing import label_binarize
1218
from sklearn.utils.multiclass import check_classification_targets
1319

@@ -133,7 +139,7 @@ class attribute, which is a dictionary `param_name: list of constraints`. See
133139
)
134140

135141

136-
class BaseSampler(SamplerMixin, _ParamsValidationMixin):
142+
class BaseSampler(SamplerMixin, OneToOneFeatureMixin, _ParamsValidationMixin):
137143
"""Base class for sampling algorithms.
138144
139145
Warning: This class should not be used directly. Use the derive classes
@@ -260,6 +266,12 @@ class FunctionSampler(BaseSampler):
260266
261267
.. versionadded:: 0.9
262268
269+
feature_names_in_ : ndarray of shape (`n_features_in_`,)
270+
Names of features seen during `fit`. Defined only when `X` has feature
271+
names that are all strings.
272+
273+
.. versionadded:: 0.10
274+
263275
See Also
264276
--------
265277
sklearn.preprocessing.FunctionTransfomer : Stateless transformer.

imblearn/combine/_smote_enn.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ class SMOTEENN(BaseSampler):
6767
6868
.. versionadded:: 0.9
6969
70+
feature_names_in_ : ndarray of shape (`n_features_in_`,)
71+
Names of features seen during `fit`. Defined only when `X` has feature
72+
names that are all strings.
73+
74+
.. versionadded:: 0.10
75+
7076
See Also
7177
--------
7278
SMOTETomek : Over-sample using SMOTE followed by under-sampling removing

imblearn/combine/_smote_tomek.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ class SMOTETomek(BaseSampler):
6666
6767
.. versionadded:: 0.9
6868
69+
feature_names_in_ : ndarray of shape (`n_features_in_`,)
70+
Names of features seen during `fit`. Defined only when `X` has feature
71+
names that are all strings.
72+
73+
.. versionadded:: 0.10
74+
6975
See Also
7076
--------
7177
SMOTEENN : Over-sample using SMOTE followed by under-sampling using Edited

imblearn/metrics/pairwise.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,17 @@ class ValueDifferenceMetric(BaseEstimator, _ParamsValidationMixin):
7171
List of length `n_features` containing the conditional probabilities
7272
for each category given a class.
7373
74+
n_features_in_ : int
75+
Number of features in the input dataset.
76+
77+
.. versionadded:: 0.10
78+
79+
feature_names_in_ : ndarray of shape (`n_features_in_`,)
80+
Names of features seen during `fit`. Defined only when `X` has feature
81+
names that are all strings.
82+
83+
.. versionadded:: 0.10
84+
7485
See Also
7586
--------
7687
sklearn.neighbors.DistanceMetric : Interface for fast metric computation.

imblearn/over_sampling/_adasyn.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ class ADASYN(BaseOverSampler):
7373
7474
.. versionadded:: 0.9
7575
76+
feature_names_in_ : ndarray of shape (`n_features_in_`,)
77+
Names of features seen during `fit`. Defined only when `X` has feature
78+
names that are all strings.
79+
80+
.. versionadded:: 0.10
81+
7682
See Also
7783
--------
7884
SMOTE : Over-sample using SMOTE.

imblearn/over_sampling/_random_over_sampler.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ class RandomOverSampler(BaseOverSampler):
7676
7777
.. versionadded:: 0.9
7878
79+
feature_names_in_ : ndarray of shape (`n_features_in_`,)
80+
Names of features seen during `fit`. Defined only when `X` has feature
81+
names that are all strings.
82+
83+
.. versionadded:: 0.10
84+
7985
See Also
8086
--------
8187
BorderlineSMOTE : Over-sample using the borderline-SMOTE variant.

imblearn/over_sampling/_smote/base.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,12 @@ class SMOTE(BaseSMOTE):
264264
265265
.. versionadded:: 0.9
266266
267+
feature_names_in_ : ndarray of shape (`n_features_in_`,)
268+
Names of features seen during `fit`. Defined only when `X` has feature
269+
names that are all strings.
270+
271+
.. versionadded:: 0.10
272+
267273
See Also
268274
--------
269275
SMOTENC : Over-sample using SMOTE for continuous and categorical features.
@@ -442,6 +448,12 @@ class SMOTENC(SMOTE):
442448
443449
.. versionadded:: 0.9
444450
451+
feature_names_in_ : ndarray of shape (`n_features_in_`,)
452+
Names of features seen during `fit`. Defined only when `X` has feature
453+
names that are all strings.
454+
455+
.. versionadded:: 0.10
456+
445457
See Also
446458
--------
447459
SMOTE : Over-sample using SMOTE.
@@ -759,6 +771,12 @@ class SMOTEN(SMOTE):
759771
760772
.. versionadded:: 0.9
761773
774+
feature_names_in_ : ndarray of shape (`n_features_in_`,)
775+
Names of features seen during `fit`. Defined only when `X` has feature
776+
names that are all strings.
777+
778+
.. versionadded:: 0.10
779+
762780
See Also
763781
--------
764782
SMOTE : Over-sample using SMOTE.

imblearn/over_sampling/_smote/cluster.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ class KMeansSMOTE(BaseSMOTE):
9393
9494
.. versionadded:: 0.9
9595
96+
feature_names_in_ : ndarray of shape (`n_features_in_`,)
97+
Names of features seen during `fit`. Defined only when `X` has feature
98+
names that are all strings.
99+
100+
.. versionadded:: 0.10
101+
96102
See Also
97103
--------
98104
SMOTE : Over-sample using SMOTE.

imblearn/over_sampling/_smote/filter.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ class BorderlineSMOTE(BaseSMOTE):
100100
101101
.. versionadded:: 0.9
102102
103+
feature_names_in_ : ndarray of shape (`n_features_in_`,)
104+
Names of features seen during `fit`. Defined only when `X` has feature
105+
names that are all strings.
106+
107+
.. versionadded:: 0.10
108+
103109
See Also
104110
--------
105111
SMOTE : Over-sample using SMOTE.
@@ -352,6 +358,12 @@ class SVMSMOTE(BaseSMOTE):
352358
353359
.. versionadded:: 0.9
354360
361+
feature_names_in_ : ndarray of shape (`n_features_in_`,)
362+
Names of features seen during `fit`. Defined only when `X` has feature
363+
names that are all strings.
364+
365+
.. versionadded:: 0.10
366+
355367
See Also
356368
--------
357369
SMOTE : Over-sample using SMOTE.

0 commit comments

Comments
 (0)