Prepare the ground
In the following exercises, you'll compare the OOB accuracy to the test set accuracy of a bagging classifier trained on the Indian Liver Patient dataset.
In sklearn, you can evaluate the OOB accuracy of an ensemble classifier by setting the parameter oob_score to True during instantiation. After training the classifier, the OOB accuracy can be obtained by accessing the .oob_score_ attribute from the corresponding instance.
In your environment, we have made available the class DecisionTreeClassifier from sklearn.tree.
Bu egzersiz
Machine Learning with Tree-Based Models in Python
kursunun bir parçasıdırEgzersiz talimatları
Import
BaggingClassifierfromsklearn.ensemble.Instantiate a
DecisionTreeClassifierwithmin_samples_leafset to 8.Instantiate a
BaggingClassifierconsisting of 50 trees and setoob_scoretoTrue.
Uygulamalı interaktif egzersiz
Bu örnek kodu tamamlayarak bu egzersizi bitirin.
# Import DecisionTreeClassifier
from sklearn.tree import DecisionTreeClassifier
# Import BaggingClassifier
____
# Instantiate dt
dt = ____(min_samples_leaf=____, random_state=1)
# Instantiate bc
bc = ____(base_estimator=____,
n_estimators=____,
oob_score=____,
random_state=1)