Construction of a random decision tree number 1, 2, 3

We construct the next three trees in a similar fashion. We should note that since the construction is random, a reader who performs another correct construction may arrive at a different construction. However, if there are sufficiently many random decision trees in a random forest, then the result of the classification should be very similar across all the random constructions.

The full construction can be found in the program output in the file source_code/4/chess.out.

Random forest graph:

Tree 0:
Root ├── [Temperature=Cold] │ ├── [Wind=None] │ │ └── [Play=Yes] │ └──[Wind=Breeze] │ └── [Play=No] ├── [Temperature=Warm] │ ├──[Wind=Breeze] │ │ └── [Play=Yes] │ └──[Wind=Strong] │ └── [Play=No] └── [Temperature=Hot] └── [Play=Yes]
Tree 1: Root ├── [Wind=Breeze] │ └── [Play=No] ├── [Wind=None] │ ├── [Temperature=Cold] │ │ └── [Play=Yes] │ ├── [Temperature=Warm] │ │ ├── [Sunshine=Sunny] │ │ │ └──[Play=Yes] │ │ └──[Sunshine=Cloudy] │ │ └── [Play=Yes] │ └── [Temperature=Hot] │ └── [Play=No] └── [Wind=Strong] ├── [Temperature=Cold] │ └── [Play=No] └── [Temperature=Warm] └── [Play=No]
Tree 2: Root ├── [Wind=Strong] │ └── [Play=No] ├── [Wind=None] │ ├── [Temperature=Cold] │ │ └── [Play=Yes] │ └── [Temperature=Warm] │ └── [Play=Yes] └── [Wind=Breeze] ├── [Temperature=Hot] │ └── [Play=Yes] └── [Temperature=Warm] └── [Play=Yes]

Tree 3: Root ├── [Temperature=Cold] │ └── [Play=No] ├── [Temperature=Warm] │ ├──[Wind=Strong] │ │ └──[Play=No] │ ├── [Wind=None] │ │ └── [Play=Yes] │ └──[Wind=Breeze] │ └── [Play=Yes] └── [Temperature=Hot] ├── [Wind=Strong] │ └── [Play=Yes] └── [Wind=Breeze] └── [Play=Yes]
The total number of trees in the random forest=4. The maximum number of the variables considered at the node is m=4.

Classification:

Given the constructed random forest we classify feature ['Warm', 'Strong', 'Sunny', '?']:

  • Tree 0 votes for the class: No
  • Tree 1 votes for the class: No
  • Tree 2 votes for the class: No
  • Tree 3 votes for the class: No

The class with the maximum number of votes is 'No'. Thus the constructed random forest classifies the feature ['Warm', 'Strong', 'Sunny', '?'] into the class 'No'.

Input:

To perform the preceding analysis, we use a program implemented earlier in this chapter. First we put the data from the table into the following CSV file:

# source_code/4/chess.csv  
Temperature,Wind,Sunshine,Play  
Cold,Strong,Cloudy,No  
Warm,Strong,Cloudy,No  
Warm,None,Sunny,Yes  
Hot,None,Sunny,No  
Hot,Breeze,Cloudy,Yes  
Warm,Breeze,Sunny,Yes  
Cold,Breeze,Cloudy,No  
Cold,None,Sunny,Yes  
Hot,Strong,Cloudy,Yes  
Warm,None,Cloudy,Yes  
Warm,Strong,Sunny,? 

Output:

We produce the output by executing on the command line:

$ python random_forest.py chess.csv 4 2 > chess.out

The number 4 here means that we want to construct four decision trees and 2 is the level of the verbosity of the program which includes the explanations of a tree is constructed. The last part > chess.out means that the output is written to the file chess.out. This file can be found in the chapter directory source_code/4. We do not put all the output here, as it is very large and repetitive. Instead some of it was included in the preceding analysis and construction of a random forest.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset