From the course: Machine Learning with Python: Decision Trees
Unlock this course with a free trial
Join today to access over 25,300 courses taught by industry experts.
How to prune a classification tree in Python - Python Tutorial
From the course: Machine Learning with Python: Decision Trees
How to prune a classification tree in Python
- [Instructor] Before we get started, know that this video is a third 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 two videos for a detailed explanation of the prior code. Now that we've trained and visualized a classification tree, let's look into what we can do to improve its performance by pruning. Decision trees are prone to overfitting. One telltale sign that a tree has overfit is if it has a high accuracy score on the training data with a low accuracy score on the test data. Let's start by getting our trees accuracy on the training data. To do this we pass the training data to the score method of the model. A model is a hundred percent accurate on a training data. That's suspicious. Let's get a second opinion from the test data. Similarly, we pass the test data to the score method of the model. Our model is 50%…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.