ComenzarEmpieza gratis

Fit a decision tree

Now, you will take a stab at building a decision tree model. The decision tree is a list of machine-learned if-else rules that decide in the telecom churn case, whether customers will churn or not. Here's an example decision tree graph built on the famous Titanic survival dataset.

The train_X, test_X, train_Y, test_Y from the previous exercise have been loaded for you. Also, the tree module and the accuracy_score function have been loaded from the sklearn library. You will now build your model and check its performance on unseen data.

Este ejercicio forma parte del curso

Machine Learning for Marketing in Python

Ver curso

Instrucciones del ejercicio

  • Initialize the decision tree model with max_depth set at 5.
  • Fit the model on the training data, first train_X, then train_Y.
  • Predict values of the testing data, or in this case test_X.
  • Measure your model's performance on the testing data by comparing between your actual test labels and predicted ones.

Ejercicio interactivo práctico

Prueba este ejercicio y completa el código de muestra.

# Initialize the model with max_depth set at 5
mytree = tree.___(max_depth = ___)

# Fit the model on the training data
treemodel = mytree.___(___, ___)

# Predict values on the testing data
pred_Y = treemodel.___(___)

# Measure model performance on testing data
accuracy_score(___, ___)
Editar y ejecutar código