ComeçarComece de graça

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.

Este exercício faz parte do curso

Machine Learning for Marketing in Python

Ver curso

Instruções do exercício

  • 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.

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

# 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))
Editar e executar o código