ComeçarComece de graça

Exporting the tree

In Decision Tree classification tasks, overfitting is usually the result of deeply grown trees. As the comparison of accuracy scores on the train and test sets shows, you have overfitting in your results. This can also be learned from the tree visualization.

In this exercise, you will export the decision tree into a text document, which can then be used for visualization.

Este exercício faz parte do curso

HR Analytics: Predicting Employee Churn in Python

Ver curso

Instruções do exercício

  • Import the the export_graphviz() function from the the sklearn.tree submodule.
  • Fit the model to the training data.
  • Export the visualization to the file tree.dot.

Exercício interativo prático

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

# Import the graphical visualization export function
from sklearn.____ import export_graphviz

# Apply Decision Tree model to fit Features to the Target
model.____(features_train,target_train)

# Export the tree to a dot file
____(model,"tree.____")
Editar e executar o código