Chapter 5:

Decision Trees and Random Forests

Learning Objectives

By the end of this chapter, you will be able to:

  • Train a decision tree model in scikit-learn
  • Use Graphviz to visualize a trained decision tree model
  • Formulate the cost functions used to split nodes in a decision tree
  • Perform a hyperparameter grid search using cross-validation with scikit-learn functions
  • Train a random forest model in scikit-learn
  • Evaluate the most important features in a random forest model

This chapter introduces decision trees and random forests in scikit-learn in addition to describing the method to perform hyperparameter grid search.


In the last two chapters, we have gained a thorough understanding of the workings of logistic regression. ...

Get Data Science Projects with Python now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.