Skip to content

Commit d6ca775

Browse files
committed
iter
1 parent c6973e5 commit d6ca775

23 files changed

+613
-6
lines changed

imblearn/base.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,13 @@ def _identity(X, y):
140140
return X, y
141141

142142

143+
def is_sampler(estimator):
144+
"""Return True if the given estimator is a sampler, False otherwise."""
145+
if estimator._estimator_type == "sampler":
146+
return True
147+
return False
148+
149+
143150
class FunctionSampler(BaseSampler):
144151
"""Construct a sampler from calling an arbitrary callable.
145152
@@ -166,9 +173,20 @@ class FunctionSampler(BaseSampler):
166173
167174
.. versionadded:: 0.6
168175
176+
Attributes
177+
----------
178+
sampling_strategy_ : dict
179+
Dictionary containing the information to sample the dataset. The keys
180+
corresponds to the class labels from which to sample and the values
181+
are the number of samples to sample.
182+
183+
n_features_in_ : int
184+
Number of features in the input dataset.
185+
186+
.. versionadded:: 0.9
187+
169188
See Also
170189
--------
171-
172190
sklearn.preprocessing.FunctionTransfomer : Stateless transformer.
173191
174192
Notes

imblearn/combine/_smote_enn.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,25 @@ class SMOTEENN(BaseSampler):
4949
5050
{n_jobs}
5151
52+
Attributes
53+
----------
54+
sampling_strategy_ : dict
55+
Dictionary containing the information to sample the dataset. The keys
56+
corresponds to the class labels from which to sample and the values
57+
are the number of samples to sample.
58+
59+
smote_ : sampler object
60+
The validated :class:`~imblearn.over_sampling.SMOTE` instance.
61+
62+
enn_ : sampler object
63+
The validated :class:`~imblearn.under_sampling.EditedNearestNeighbours`
64+
instance.
65+
66+
n_features_in_ : int
67+
Number of features in the input dataset.
68+
69+
.. versionadded:: 0.9
70+
5271
See Also
5372
--------
5473
SMOTETomek : Over-sample using SMOTE followed by under-sampling removing

imblearn/combine/_smote_tomek.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,24 @@ class SMOTETomek(BaseSampler):
4949
5050
{n_jobs}
5151
52+
Attributes
53+
----------
54+
sampling_strategy_ : dict
55+
Dictionary containing the information to sample the dataset. The keys
56+
corresponds to the class labels from which to sample and the values
57+
are the number of samples to sample.
58+
59+
smote_ : sampler object
60+
The validated :class:`~imblearn.over_sampling.SMOTE` instance.
61+
62+
tomek_ : sampler object
63+
The validated :class:`~imblearn.under_sampling.TomekLinks` instance.
64+
65+
n_features_in_ : int
66+
Number of features in the input dataset.
67+
68+
.. versionadded:: 0.9
69+
5270
See Also
5371
--------
5472
SMOTEENN : Over-sample using SMOTE followed by under-sampling using Edited

imblearn/ensemble/_bagging.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ class BalancedBaggingClassifier(BaggingClassifier):
111111
estimators_ : list of estimators
112112
The collection of fitted base estimators.
113113
114+
sampler_ : sampler object
115+
The validate sampler created from the `sampler` parameter.
116+
114117
estimators_samples_ : list of ndarray
115118
The subset of drawn samples (i.e., the in-bag samples) for each base
116119
estimator. Each subset is defined by a boolean mask.
@@ -133,6 +136,11 @@ class BalancedBaggingClassifier(BaggingClassifier):
133136
was never left out during the bootstrap. In this case,
134137
``oob_decision_function_`` might contain NaN.
135138
139+
n_features_in_ : int
140+
Number of features in the input dataset.
141+
142+
.. versionadded:: 0.9
143+
136144
See Also
137145
--------
138146
BalancedRandomForestClassifier : Random forest applying random-under

imblearn/ensemble/_easy_ensemble.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,23 @@ class EasyEnsembleClassifier(BaggingClassifier):
7373
estimators_ : list of estimators
7474
The collection of fitted base estimators.
7575
76+
estimators_samples_ : list of arrays
77+
The subset of drawn samples for each base estimator.
78+
79+
estimators_features_ : list of arrays
80+
The subset of drawn features for each base estimator.
81+
7682
classes_ : array, shape (n_classes,)
7783
The classes labels.
7884
7985
n_classes_ : int or list
8086
The number of classes.
8187
88+
n_features_in_ : int
89+
Number of features in the input dataset.
90+
91+
.. versionadded:: 0.9
92+
8293
See Also
8394
--------
8495
BalancedBaggingClassifier : Bagging classifier for which each base

imblearn/ensemble/_forest.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,17 @@ class BalancedRandomForestClassifier(RandomForestClassifier):
230230
231231
Attributes
232232
----------
233-
estimators_ : list of DecisionTreeClassifier
233+
base_estimator_ : :class:`~sklearn.tree.DecisionTreeClassifier` instance
234+
The child estimator template used to create the collection of fitted
235+
sub-estimators.
236+
237+
estimators_ : list of :class:`~sklearn.tree.DecisionTreeClassifier`
234238
The collection of fitted sub-estimators.
235239
236-
samplers_ : list of RandomUnderSampler
240+
base_sampler_ : :class:`~imblearn.under_sampling.RandomUnderSampler`
241+
The base sampler used to construct the subsequent list of samplers.
242+
243+
samplers_ : list of :class:`~imblearn.under_sampling.RandomUnderSampler`
237244
The collection of fitted samplers.
238245
239246
pipelines_ : list of Pipeline.
@@ -250,6 +257,11 @@ class labels (multi-output problem).
250257
n_features_ : int
251258
The number of features when ``fit`` is performed.
252259
260+
n_features_in_ : int
261+
Number of features in the input dataset.
262+
263+
.. versionadded:: 0.9
264+
253265
n_outputs_ : int
254266
The number of outputs when ``fit`` is performed.
255267
@@ -628,7 +640,7 @@ def _set_oob_score(self, X, y):
628640
@property
629641
def n_features_(self):
630642
"""Number of features when fitting the estimator."""
631-
return getattr(self.n_features_in_, self._n_features)
643+
return getattr(self.n_features_in_, "n_features_", self._n_features)
632644

633645
def _more_tags(self):
634646
return {

imblearn/ensemble/_weight_boosting.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ class RUSBoostClassifier(AdaBoostClassifier):
6868
estimators_ : list of classifiers
6969
The collection of fitted sub-estimators.
7070
71-
samplers_ : list of RandomUnderSampler
71+
base_sampler_ : :class:`~imblearn.under_sampling.RandomUnderSampler`
72+
The base sampler used to generate the subsequent samplers.
73+
74+
samplers_ : list of :class:`~imblearn.under_sampling.RandomUnderSampler`
7275
The collection of fitted samplers.
7376
7477
pipelines_ : list of Pipeline
@@ -90,6 +93,11 @@ class RUSBoostClassifier(AdaBoostClassifier):
9093
feature_importances_ : ndarray of shape (n_features,)
9194
The feature importances if supported by the ``base_estimator``.
9295
96+
n_features_in_ : int
97+
Number of features in the input dataset.
98+
99+
.. versionadded:: 0.9
100+
93101
See Also
94102
--------
95103
BalancedBaggingClassifier : Bagging classifier for which each base

imblearn/over_sampling/_adasyn.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,21 @@ class ADASYN(BaseOverSampler):
4646
4747
{n_jobs}
4848
49+
Attributes
50+
----------
51+
sampling_strategy_ : dict
52+
Dictionary containing the information to sample the dataset. The keys
53+
corresponds to the class labels from which to sample and the values
54+
are the number of samples to sample.
55+
56+
nn_ : estimator object
57+
Validated K-nearest Neighbours estimator linked to the parameter `n_neighbors`.
58+
59+
n_features_in_ : int
60+
Number of features in the input dataset.
61+
62+
.. versionadded:: 0.9
63+
4964
See Also
5065
--------
5166
SMOTE : Over-sample using SMOTE.

imblearn/over_sampling/_random_over_sampler.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ class RandomOverSampler(BaseOverSampler):
5757
5858
Attributes
5959
----------
60+
sampling_strategy_ : dict
61+
Dictionary containing the information to sample the dataset. The keys
62+
corresponds to the class labels from which to sample and the values
63+
are the number of samples to sample.
64+
6065
sample_indices_ : ndarray of shape (n_new_samples,)
6166
Indices of the samples selected.
6267
@@ -68,6 +73,11 @@ class RandomOverSampler(BaseOverSampler):
6873
6974
.. versionadded:: 0.8
7075
76+
n_features_in_ : int
77+
Number of features in the input dataset.
78+
79+
.. versionadded:: 0.9
80+
7181
See Also
7282
--------
7383
BorderlineSMOTE : Over-sample using the borderline-SMOTE variant.

imblearn/over_sampling/_smote/base.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,21 @@ class SMOTE(BaseSMOTE):
231231
232232
{n_jobs}
233233
234+
Attributes
235+
----------
236+
sampling_strategy_ : dict
237+
Dictionary containing the information to sample the dataset. The keys
238+
corresponds to the class labels from which to sample and the values
239+
are the number of samples to sample.
240+
241+
nn_k_ : estimator object
242+
Validated k-nearest neighbours created from the `k_neighbors` parameter.
243+
244+
n_features_in_ : int
245+
Number of features in the input dataset.
246+
247+
.. versionadded:: 0.9
248+
234249
See Also
235250
--------
236251
SMOTENC : Over-sample using SMOTE for continuous and categorical features.
@@ -628,6 +643,21 @@ class SMOTEN(SMOTE):
628643
629644
{n_jobs}
630645
646+
Attributes
647+
----------
648+
sampling_strategy_ : dict
649+
Dictionary containing the information to sample the dataset. The keys
650+
corresponds to the class labels from which to sample and the values
651+
are the number of samples to sample.
652+
653+
nn_k_ : estimator object
654+
Validated k-nearest neighbours created from the `k_neighbors` parameter.
655+
656+
n_features_in_ : int
657+
Number of features in the input dataset.
658+
659+
.. versionadded:: 0.9
660+
631661
See Also
632662
--------
633663
SMOTE : Over-sample using SMOTE.

imblearn/over_sampling/_smote/cluster.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ class KMeansSMOTE(BaseSMOTE):
6969
7070
Attributes
7171
----------
72+
sampling_strategy_ : dict
73+
Dictionary containing the information to sample the dataset. The keys
74+
corresponds to the class labels from which to sample and the values
75+
are the number of samples to sample.
76+
7277
kmeans_estimator_ : estimator
7378
The fitted clustering method used before to apply SMOTE.
7479
@@ -78,6 +83,11 @@ class KMeansSMOTE(BaseSMOTE):
7883
cluster_balance_threshold_ : float
7984
The threshold used during ``fit`` for calling a cluster balanced.
8085
86+
n_features_in_ : int
87+
Number of features in the input dataset.
88+
89+
.. versionadded:: 0.9
90+
8191
See Also
8292
--------
8393
SMOTE : Over-sample using SMOTE.

imblearn/over_sampling/_smote/filter.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,24 @@ class BorderlineSMOTE(BaseSMOTE):
6565
The type of SMOTE algorithm to use one of the following options:
6666
``'borderline-1'``, ``'borderline-2'``.
6767
68+
Attributes
69+
----------
70+
sampling_strategy_ : dict
71+
Dictionary containing the information to sample the dataset. The keys
72+
corresponds to the class labels from which to sample and the values
73+
are the number of samples to sample.
74+
75+
nn_k_ : estimator object
76+
Validated k-nearest neighbours created from the `k_neighbors` parameter.
77+
78+
nn_m_ : estimator object
79+
Validated m-nearest neighbours created from the `m_neighbors` parameter.
80+
81+
n_features_in_ : int
82+
Number of features in the input dataset.
83+
84+
.. versionadded:: 0.9
85+
6886
See Also
6987
--------
7088
SMOTE : Over-sample using SMOTE.
@@ -264,6 +282,28 @@ class SVMSMOTE(BaseSMOTE):
264282
out_step : float, default=0.5
265283
Step size when extrapolating.
266284
285+
Attributes
286+
----------
287+
sampling_strategy_ : dict
288+
Dictionary containing the information to sample the dataset. The keys
289+
corresponds to the class labels from which to sample and the values
290+
are the number of samples to sample.
291+
292+
nn_k_ : estimator object
293+
Validated k-nearest neighbours created from the `k_neighbors` parameter.
294+
295+
nn_m_ : estimator object
296+
Validated m-nearest neighbours created from the `m_neighbors` parameter.
297+
298+
svm_estimator_ : estimator object
299+
The validated SVM classifier used to detect samples from which to
300+
generate new synthetic samples.
301+
302+
n_features_in_ : int
303+
Number of features in the input dataset.
304+
305+
.. versionadded:: 0.9
306+
267307
See Also
268308
--------
269309
SMOTE : Over-sample using SMOTE.

imblearn/pipeline.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ class Pipeline(pipeline.Pipeline):
6767
Read-only attribute to access any step parameter by user given name.
6868
Keys are step names and values are steps parameters.
6969
70+
classes_ : ndarray of shape (n_classes,)
71+
The classes labels.
72+
73+
n_features_in_ : int
74+
Number of features seen during first step `fit` method.
75+
7076
See Also
7177
--------
7278
make_pipeline : Helper function to make pipeline.

0 commit comments

Comments
 (0)