Implementation of random forest algorithm

We implement a random forest algorithm using a modified decision tree algorithm from the previous chapter. We also add an option to set a verbose mode within the program that can describe the whole process of how the algorithm works on a specific input- how a random forest is constructed with its random decision trees and how this constructed random forest is used to classify other features.

The implementation of a random forest uses the construction of a decision tree from the previous chapter. A reader is encouraged to consult the function decision_tree.construct_general_tree from the previous chapter:

# source_code/4/random_forest.pyimport mathimport randomimport syssys.path.append('../common') ...

Get Data Science Algorithms in a Week now with O’Reilly online learning.

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