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.
You are encouraged to consult the decision_tree.construct_general_tree function from the previous chapter:
# source_code/4/random_forest.pyimport mathimport randomimport syssys.path.append('../common')import common # noqaimport decision_tree # noqafrom common import printfv # noqa#Random forest construction ...