Page 107 - Data Science Algorithms in a Week
P. 107

Random Forest


            In the previous chapter, decision trees were not able to classify the feature (Cold, None).
            So, this time, we would like to find, using the random forest algorithm, whether Jane would
            go shopping if the outside temperature was cold and there was no rain.

            Analysis:
            To perform the analysis with the random forest algorithm we use the implemented
            program.

            Input:
            We put the data from the table into the CSV file:

                # source_code/4/shopping.csv
                Temperature,Rain,Shopping
                Cold,None,Yes
                Warm,None,No
                Cold,Strong,Yes
                Cold,None,No
                Warm,Strong,No
                Warm,None,Yes
                Cold,None,?
            Output:

            We want to use a slightly larger number of the trees that we used in the previous examples
            and explanations to get more accurate results. We want to construct a random forest with 20
            trees with the output of the low verbosity - level 0. Thus, we execute in a terminal:

                $ python random_forest.py shopping.csv 20 0
                ***Classification***
                Feature: ['Cold', 'None', '?']
                Tree 0 votes for the class: Yes
                Tree 1 votes for the class: No
                Tree 2 votes for the class: No
                Tree 3 votes for the class: No
                Tree 4 votes for the class: No
                Tree 5 votes for the class: Yes
                Tree 6 votes for the class: Yes
                Tree 7 votes for the class: Yes
                Tree 8 votes for the class: No
                Tree 9 votes for the class: Yes
                Tree 10 votes for the class: Yes
                Tree 11 votes for the class: Yes
                Tree 12 votes for the class: Yes
                Tree 13 votes for the class: Yes
                Tree 14 votes for the class: Yes


                                                     [ 95 ]
   102   103   104   105   106   107   108   109   110   111   112