1. Learn
  2. /
  3. Courses
  4. /
  5. Machine Learning for Marketing in Python

Connected

Exercise

Break down decision tree rules

In this exercise you will extract the if-else rules from the decision tree and plot them to identify the main drivers of the churn.

The fitted decision tree instance is loaded as mytree and the scaled features are loaded as a pandas DataFrame called train_X. The tree module from sklearn library and the graphviz library have been already loaded for you.

Note that we've used a proprietary display_image() function instead of display(graph) to make it easier for you to view the output.

Instructions

100 XP
  • Export the graphviz object from the trained decision tree .
  • Assign the feature names.
  • Set the precision to 1 and add the class names.
  • Call the Source() function from graphviz and pass the exported graphviz object.