LoslegenKostenlos loslegen

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.

Diese Übung ist Teil des Kurses

Machine Learning for Marketing in Python

Kurs anzeigen

Anleitung zur Übung

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

Interaktive Übung

Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.

# 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))
Code bearbeiten und ausführen