BaşlayınÜcretsiz Başlayın

Bagging: the scikit-learn way

Let's now apply scikit-learn's BaggingClassifier to the Pokémon dataset.

You obtained an F1 score of around 0.63 with your custom bagging ensemble.

Will BaggingClassifier() beat it? Time to find out!

Bu egzersiz

Ensemble Methods in Python

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • Instantiate the base model, clf_dt: a "restricted" decision tree with a max depth of 4.
  • Build a bagging classifier with the decision tree as base estimator, using 21 estimators.
  • Predict the labels of the test set.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

# Instantiate the base model
clf_dt = ____

# Build the Bagging classifier
clf_bag = ____(____, ____, random_state=500)

# Fit the Bagging model to the training set
clf_bag.fit(X_train, y_train)

# Predict the labels of the test set
pred = ____

# Show the F1-score
print('F1-Score: {:.3f}'.format(f1_score(y_test, pred)))
Kodu Düzenle ve Çalıştır