Get startedGet started for free

OOB Score vs Test Set Score

Now that you instantiated bc, you will fit it to the training set and evaluate its test set and OOB accuracies.

The dataset is processed for you and split into 80% train and 20% test. The feature matrices X_train and X_test, as well as the arrays of labels y_train and y_test are available in your workspace. In addition, we have also loaded the classifier bc instantiated in the previous exercise and the function accuracy_score() from sklearn.metrics.

This exercise is part of the course

Machine Learning with Tree-Based Models in Python

View Course

Exercise instructions

  • Fit bc to the training set and predict the test set labels and assign the results to y_pred.

  • Evaluate the test set accuracy acc_test by calling accuracy_score.

  • Evaluate bc's OOB accuracy acc_oob by extracting the attribute oob_score_ from bc.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Fit bc to the training set 
____.____(____, ____)

# Predict test set labels
y_pred = ____.____(____)

# Evaluate test set accuracy
acc_test = ____(____, ____)

# Evaluate OOB accuracy
acc_oob = ____.____

# Print acc_test and acc_oob
print('Test set accuracy: {:.3f}, OOB accuracy: {:.3f}'.format(acc_test, acc_oob))
Edit and Run Code