1
$\begingroup$

If in bagging we defined our own tuned decision tree as estimator with max features as parameter in that estimator rather than taking by default decision tree estimator available in BaggingClassifer in sckit learn? Will this bagging be equivalent to Random forest then?

dct= DecisionTreeClassifier(max_features=4,random_state=2021)

model_bg=BaggingRegressor(base_estimator=dct,random_state=2021,oob_score=True,max_features = X_train.shape[1],n_estimators=15,max_samples=X_train.shape[0])

$\endgroup$

1 Answer 1

1
$\begingroup$

From the documentation:

A Bagging classifier is an ensemble meta-estimator that fits base classifiers each on random subsets of the original dataset and then aggregate their individual predictions (either by voting or by averaging) to form a final prediction. […]

bootstrap: bool, default=True
Whether samples are drawn with replacement. If False, sampling without replacement is performed.

bootstrap_features: bool, default=False
Whether features are drawn with replacement.

Random forest is just a bagging classifier (or regressor) using trees as base classifiers. It by default resamples both rows (samples) and columns (features).

Notice that you don't want to use the same random seed for each tree, because you want the base classifiers to be randomly different. Other arguments like max_depth can be passed to random forest directly. Almost always you should just use the random forest, rather than constructing it yourself since the build-in implementation is already tested and optimized for the task.

$\endgroup$
4
  • $\begingroup$ hi that was max_features i want to wrote and not max_depth. I am new in ML. So do you mean it will act as a random forest however there is a ready made implementation of that so we dont create it by ourself? Please confirm $\endgroup$ Commented Aug 2, 2021 at 20:13
  • $\begingroup$ @RaufurKhan yes, this is what I'm saying. If you don't have very good reason to do so, do not re-invent the wheel, this usually backfires. $\endgroup$
    – Tim
    Commented Aug 2, 2021 at 20:40
  • $\begingroup$ Thank you very much tim😄 $\endgroup$ Commented Aug 3, 2021 at 14:35
  • $\begingroup$ @RaufurKhan if this answers your question, please mark it as "solved". $\endgroup$
    – Tim
    Commented Aug 4, 2021 at 8:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.