Get startedGet started for free

Fit decision tree model

Now you will fit a decision tree on the training set of the telecom dataset, and then predict labels on the unseen testing data, and calculate the accuracy of your model predictions. You will see the difference in the performance compared to the logistic regression.

The accuracy_score function has been imported, also the training and testing datasets that you've built previously have been loaded as train_X and test_X for features, and train_Y and test_Y for target variables.

This exercise is part of the course

Machine Learning for Marketing in Python

View Course

Exercise instructions

  • Initialize a decision tree classifier.
  • Fit the decision tree on the training data.
  • Predict churn labels on the testing data.
  • Calculate and print the accuracy score on the testing data.

Hands-on interactive exercise

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

# Initialize decision tree classifier
mytree = tree.___()

# Fit the decision tree on training data
mytree.___(___, ___)

# Predict churn labels on testing data
pred_test_Y = ___.___(___)

# Calculate accuracy score on testing data
test_accuracy = ___(___, ___)

# Print test accuracy
print('Test accuracy:', round(___, 4))
Edit and Run Code