A Decision Tree Algorithm

A decision tree is a commonly used algorithm used in classification – an important Machine Learning topic. Example uses include[i]:

·      Investment modelling

·      Event location planning

·      Immunization awareness campaign planning

·      How to increase tourist numbers to a city

·      Managing flooding risks

They have flow-chart-like structures where each internal (non-leaf) node denotes a test on an attribute, each branch represents the outcome of a test, and each leaf (or terminal) node has a label. The topmost node in a tree is the ‘root node’.

Below is an example decision tree algorithm used for classifying vertebrates:


[i] https://github.com/SilverDecisions/SilverDecisions/wiki/Gallery



Figure 23. A decision tree, used for classification


Below is Python code for running the vertebrate classification algorithm as a game in which a user looks at a vertebrate and answers a series of questions. 

Key parts of the code are as follows:

Line 9. This line creates a variable called “feathers”. This is stored in memory along with a value that is attached to it. The value (y/n) is inputted by the user. Writing ‘input’ tells the program to ask for a value to be inputted, and this value then becomes attached to the variable in memory.  

Lines 10 contains an “if statement”. If statements say “if the value attributed to ‘a’ is ‘b’, then do ‘c’. In this case ‘c’ is the print statement in Line 11 that displays “It’s a Bird”.

“==” in Line 10 means ‘compare’.   

Complete and Continue