Bagging example
In the following example, we will use the Python scikit-learn library to instantiate an object of the BaggingClassifier class, which is passed as a parameter and basic classifier of the DecisionTreeClassifier type; the number of basic estimators of the DecisionTreeClassifier type to be instantiated is set with the n_estimators parameter.
It is possible to invoke on the bagging instance of the BaggingClassifier type and the fit() and predict() methods, which are usually invoked on the common classifiers.
As we already know, the bagging method uses sampling replacement. Due to this, we can set the maximum number of samples to associate with each basic estimator (using the max_samples parameter and activate the bootstrap mechanism ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access