BaşlayınÜcretsiz Başlayın

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.

Bu egzersiz

Machine Learning for Marketing in Python

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

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

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

# Export graphviz object from the trained decision tree 
exported = tree.___(decision_tree=mytree, 
			# Assign feature names
            out_file=None, ___=train_X.columns, 
			# Set precision to 1 and add class names
			precision=1, ___=['Not churn','Churn'], filled = True)

# Call the Source function and pass the exported graphviz object
graph = graphviz.___(exported)

# Display the decision tree
display_image("/usr/local/share/datasets/decision_tree_rules.png")
Kodu Düzenle ve Çalıştır