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

Decision Trees


            IG(S,wind) and IG(S,temperature) are greater than IG(S,sunshine). Both of them are equal;
            therefore, we can choose any of the attribute to form the three branches; for example, the
            first one, temperature. In that case, each of the three branches would have data samples S ,
                                                                                               cold
            S warn , S . At those branches, we could apply the algorithm further to form the rest of the
                  hot
            decision tree. Instead, we will use the program to complete the tree.
            Input:

                source_code/3/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
            Output:

                $ python construct_decision_tree.py chess.csv 0
                Root
                ├── [Temperature=Cold]
                │ ├── [Wind=Breeze]
                │ │ └── [Play=No]
                │ ├── [Wind=Strong]
                │ │ └── [Play=No]
                │ └── [Wind=None]
                │   └── [Play=Yes]
                ├── [Temperature=Warm]
                │ ├── [Wind=Breeze]
                │ │ └── [Play=Yes]
                │ ├── [Wind=None]
                │ │ ├── [Sunshine=Sunny]
                │ │ │ └── [Play=Yes]
                │ │ └── [Sunshine=Cloudy]
                │ │   └── [Play=Yes]
                │ └── [Wind=Strong]
                │   └── [Play=No]
                └── [Temperature=Hot]
                    ├── [Wind=Strong]
                    │ └── [Play=Yes]
                    ├── [Wind=None]
                    │ └── [Play=No]


                                                     [ 68 ]
   75   76   77   78   79   80   81   82   83   84   85