Reputation: 51
I'm getting an error for the BaggingClassifier in scikit-learn 0.22.2.post1. I'm using python 3.8.2.
from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import BaggingClassifier
bag_clf = BaggingClassifier(
DecisionTreeClassifier(
random_state=0,
criterion='entropy'
),
n_estimators=100,
max_samples=100,
max_depth=2,
bootstrap=True,
random_state=0
)
TypeError: init() got an unexpected keyword argument 'max_depth'
If I delete max_depth=2
, from my code I can create the object. max_depth=2
is the only argument for which I get the error.
Anyone know what's going on here?
Upvotes: 0
Views: 4101
Reputation: 60321
max_depth
is an argument of DecisionTreeClassifier
(docs), not of BaggingClassifier
(docs); you should change the definition to
bag_clf = BaggingClassifier(
DecisionTreeClassifier( max_depth=2,
random_state=0,
criterion='entropy'
),
n_estimators=100,
max_samples=100,
bootstrap=True,
random_state=0
)
Upvotes: 1