From the course: Machine Learning with Python: Decision Trees

Unlock the full course today

Join today to access over 24,700 courses taught by industry experts.

How to visualize a classification tree in Python

How to visualize a classification tree in Python - Python Tutorial

From the course: Machine Learning with Python: Decision Trees

How to visualize a classification tree in Python

- [Instructor] Before we get started, note that this video is a second in a three video sequence that explains how to build, visualize, and prune a classification tree. So if you have not done so, watch the previous video for a detailed explanation of the prior code. Now that we've trained a classification tree, let's visualize it to get a better understanding of the tree logic. First, we make sure that we import the tree object from the sklearn package. The figure_method of Pyplot allows us to specify the size of our tree. Feel free to adjust this to see how it impacts the size of your tree. Finally, we use the plot_tree method of the tree object to visualize the tree. The first argument we pass to this method is the classification tree model itself, model. Then we specify the independent variables as a list. Next, we specify the possible values of the dependent variable as a list in ascending order, No and Yes.…

Contents