MulaiMulai sekarang secara gratis

Evaluate the classification tree

Now that you've fit your first classification tree, it's time to evaluate its performance on the test set. You'll do so using the accuracy metric which corresponds to the fraction of correct predictions made on the test set.

The trained model dt from the previous exercise is loaded in your workspace along with the test set features matrix X_test and the array of labels y_test.

Latihan ini adalah bagian dari kursus

Machine Learning with Tree-Based Models in Python

Lihat Kursus

Petunjuk latihan

  • Import the function accuracy_score from sklearn.metrics.

  • Predict the test set labels and assign the obtained array to y_pred.

  • Evaluate the test set accuracy score of dt by calling accuracy_score() and assign the value to acc.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# Import accuracy_score
from ____.____ import ____

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

# Compute test set accuracy  
acc = ____(____, ____)
print("Test set accuracy: {:.2f}".format(acc))
Edit dan Jalankan Kode