Skip to content

Commit

Permalink
FIX correct how Baggings detect sample_weight support (fix #5)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhiningLiu1998 committed Oct 22, 2021
1 parent 1cdf6a7 commit e246857
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions imbalanced_ensemble/ensemble/_bagging.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from sklearn.base import clone
from sklearn.ensemble import BaggingClassifier
from sklearn.ensemble._base import _partition_estimators
from sklearn.pipeline import Pipeline as skPipeline
from sklearn.tree import DecisionTreeClassifier
from sklearn.utils import check_random_state
from sklearn.utils.validation import _check_sample_weight, has_fit_parameter
Expand Down Expand Up @@ -94,8 +95,12 @@ def _parallel_build_estimators(n_estimators, ensemble, X, y, sample_weight,
max_samples = ensemble._max_samples
bootstrap = ensemble.bootstrap
bootstrap_features = ensemble.bootstrap_features
support_sample_weight = has_fit_parameter(ensemble.base_estimator_,
"sample_weight")

# Check if the base_estimator supports sample_weight
base_estimator_ = ensemble.base_estimator_
while (isinstance(base_estimator_, skPipeline)): # for Pipelines
base_estimator_ = base_estimator_._final_estimator
support_sample_weight = has_fit_parameter(base_estimator_, "sample_weight")
if not support_sample_weight and sample_weight is not None:
raise ValueError("The base estimator doesn't support sample weight")

Expand Down

0 comments on commit e246857

Please sign in to comment.