Skip to content

Commit dc0b74b

Browse files
FIX AttributeError related to n_features_ (fix #6)
1 parent 5b17c6c commit dc0b74b

File tree

9 files changed

+18
-18
lines changed

9 files changed

+18
-18
lines changed

imbalanced_ensemble/ensemble/_bagging.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ def _fit(self, X, y,
361361
sample_weight = _check_sample_weight(sample_weight, X, dtype=None)
362362

363363
# Remap output
364-
n_samples, self.n_features_ = X.shape
364+
n_samples, self.n_features_in_ = X.shape
365365
self._n_samples = n_samples
366366
y = self._validate_y(y)
367367

@@ -384,11 +384,11 @@ def _fit(self, X, y,
384384
if isinstance(self.max_features, numbers.Integral):
385385
max_features = self.max_features
386386
elif isinstance(self.max_features, float):
387-
max_features = self.max_features * self.n_features_
387+
max_features = self.max_features * self.n_features_in_
388388
else:
389389
raise ValueError("max_features must be int or float")
390390

391-
if not (0 < max_features <= self.n_features_):
391+
if not (0 < max_features <= self.n_features_in_):
392392
raise ValueError("max_features must be in (0, n_features]")
393393

394394
max_features = max(1, int(max_features))

imbalanced_ensemble/ensemble/base.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -479,8 +479,8 @@ def fit(self, X, y, *, sample_weight=None, **kwargs):
479479
raise ValueError("sample_weight cannot contain negative weights")
480480

481481
# Remap output
482-
n_samples, self.n_features_ = X.shape
483-
self.features_ = np.arange(self.n_features_)
482+
n_samples, self.n_features_in_ = X.shape
483+
self.features_ = np.arange(self.n_features_in_)
484484
self._n_samples = n_samples
485485
y = self._validate_y(y)
486486
self._encode_map = {c: np.where(self.classes_==c)[0][0] for c in self.classes_}
@@ -534,11 +534,11 @@ def predict_proba(self, X):
534534
X, accept_sparse=['csr', 'csc'], dtype=None,
535535
force_all_finite=False
536536
)
537-
if self.n_features_ != X.shape[1]:
537+
if self.n_features_in_ != X.shape[1]:
538538
raise ValueError("Number of features of the model must "
539539
"match the input. Model n_features is {0} and "
540540
"input n_features is {1}."
541-
"".format(self.n_features_, X.shape[1]))
541+
"".format(self.n_features_in_, X.shape[1]))
542542

543543
# Parallel loop
544544
n_jobs, _, starts = _partition_estimators(self.n_estimators,

imbalanced_ensemble/ensemble/compatible/bagging_compatible.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class CompatibleBaggingClassifier(ImbalancedEnsembleClassifierMixin,
133133
base_estimator_ : estimator
134134
The base estimator from which the ensemble is grown.
135135
136-
n_features_ : int
136+
n_features_in_ : int
137137
The number of features when :meth:`fit` is performed.
138138
139139
estimators_ : list of estimators
@@ -297,7 +297,7 @@ def fit(self, X, y,
297297
sample_weight = _check_sample_weight(sample_weight, X, dtype=None)
298298

299299
# Remap output
300-
n_samples, self.n_features_ = X.shape
300+
n_samples, self.n_features_in_ = X.shape
301301
self._n_samples = n_samples
302302
y = self._validate_y(y)
303303

@@ -320,11 +320,11 @@ def fit(self, X, y,
320320
if isinstance(self.max_features, numbers.Integral):
321321
max_features = self.max_features
322322
elif isinstance(self.max_features, float):
323-
max_features = self.max_features * self.n_features_
323+
max_features = self.max_features * self.n_features_in_
324324
else:
325325
raise ValueError("max_features must be int or float")
326326

327-
if not (0 < max_features <= self.n_features_):
327+
if not (0 < max_features <= self.n_features_in_):
328328
raise ValueError("max_features must be in (0, n_features]")
329329

330330
max_features = max(1, int(max_features))

imbalanced_ensemble/ensemble/over_sampling/over_bagging.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class OverBaggingClassifier(ResampleBaggingClassifier):
116116
estimators_ : list of classifiers
117117
The collection of fitted sub-estimators.
118118
119-
n_features_ : int
119+
n_features_in_ : int
120120
The number of features when :meth:`fit` is performed.
121121
122122
estimators_ : list of estimators

imbalanced_ensemble/ensemble/over_sampling/smote_bagging.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ class SMOTEBaggingClassifier(ResampleBaggingClassifier):
125125
estimators_ : list of classifiers
126126
The collection of fitted sub-estimators.
127127
128-
n_features_ : int
128+
n_features_in_ : int
129129
The number of features when :meth:`fit` is performed.
130130
131131
estimators_ : list of estimators

imbalanced_ensemble/ensemble/under_sampling/balanced_random_forest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ class labels (multi-output problem).
280280
The number of classes (single output problem), or a list containing the
281281
number of classes for each output (multi-output problem).
282282
283-
n_features_ : int
283+
n_features_in_ : int
284284
The number of features when ``fit`` is performed.
285285
286286
n_outputs_ : int
@@ -485,7 +485,7 @@ def fit(self, X, y,
485485
X.sort_indices()
486486

487487
# Remap output
488-
_, self.n_features_ = X.shape
488+
_, self.n_features_in_ = X.shape
489489

490490
y = np.atleast_1d(y)
491491
if y.ndim == 2 and y.shape[1] == 1:

imbalanced_ensemble/ensemble/under_sampling/easy_ensemble.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class EasyEnsembleClassifier(ResampleBaggingClassifier):
118118
estimators_ : list of classifiers
119119
The collection of fitted sub-estimators.
120120
121-
n_features_ : int
121+
n_features_in_ : int
122122
The number of features when :meth:`fit` is performed.
123123
124124
estimators_ : list of estimators

imbalanced_ensemble/ensemble/under_sampling/under_bagging.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class UnderBaggingClassifier(ResampleBaggingClassifier):
114114
estimators_ : list of classifiers
115115
The collection of fitted sub-estimators.
116116
117-
n_features_ : int
117+
n_features_in_ : int
118118
The number of features when :meth:`fit` is performed.
119119
120120
estimators_ : list of estimators

imbalanced_ensemble/utils/_validation_param.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ def check_visualizer_ensembles(ensembles:dict, eval_datasets_:dict, eval_metrics
577577
names_imbalanced_ensemble.append(name)
578578
names_sklearn_ensemble = list(set(ensembles.keys()) - set(names_imbalanced_ensemble))
579579

580-
# Raise error if not all ensembles have the same n_features_
580+
# Raise error if not all ensembles have the same n_features_/n_features_in_
581581
n_features_fitted = _check_all_estimators_have_same_attribute(ensembles,
582582
attr_alias = ('n_features_', 'n_features_in_'))
583583

0 commit comments

Comments
 (0)