Entropy vs Gini index
In this exercise you'll compare the test set accuracy of dt_entropy
to the accuracy of another tree named dt_gini
. The tree dt_gini
was trained on the same dataset using the same parameters except for the information criterion which was set to the gini index using the keyword 'gini'
.
X_test
, y_test
, dt_entropy
, as well as accuracy_gini
which corresponds to the test set accuracy achieved by dt_gini
are available in your workspace.
This exercise is part of the course
Machine Learning with Tree-Based Models in Python
Exercise instructions
- Import
accuracy_score
fromsklearn.metrics
. - Predict the test set labels of
dt_entropy
and assign the result toy_pred
. - Evaluate the test set accuracy of
dt_entropy
and assign the result toaccuracy_entropy
. - Review
accuracy_entropy
andaccuracy_gini
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Import accuracy_score from sklearn.metrics
from ____.____ import ____
# Use dt_entropy to predict test set labels
____= ____.____(____)
# Evaluate accuracy_entropy
accuracy_entropy = ____(____, ____)
# Print accuracy_entropy
print(f'Accuracy achieved by using entropy: {accuracy_entropy:.3f}')
# Print accuracy_gini
print(f'Accuracy achieved by using the gini index: {accuracy_gini:.3f}')