Decision Tree
AI 101
Trees and Keys
We return to the question of film with:
- More understanding of Colab, and…
- More understanding of classification.
What is a Decision tree?
- A decision tree is a flowchart-like structure in which each internal step represents a feature, and each end point node represents a label.
- The paths from root to leaf represent classification rules.
- A dichotomous key is a decision tree that can be used for classification.
- In our case with oaks, a “tree tree” - or an “oak decision tree”.
The Key
- Recall, a key is a branching series of yes/no questions.
- The dichotomous key gets its name from having two (“di”) possibilities for any case
- “yes” and “no” or “true” and “false” or etc. etc.
- To classify an oak, there are a series of questions that a non-expert can answer by inspecting the tree, such as being looking at the whole tree or looking at its leaves.
- After answer a question, there is either a reference to a new question, usually by number, or a note that you have determined what the type of tree is.
Features
We now recognize these “yes”/“no” questions as features.
We recall:
- You may have to zoom in…
- If you turn it upside down, it somewhat looks like a tree (hence the name).
Our Films
- We return to the films from the classification lecture.
- We will not interact with Gemini today…
- Rather, create a “program” of sorts that will ask us questions and determine a film.
- Create a script which will ask you a series of yes/no questions about a film and then eventually tell you which film you are thinking off.
- While you may use multiple cells, your ultimate result should be a single code cell (like below).
Simple Example
- Try this out.
Easy Mode
- Create a simple program to differentiate the three most recent Alien films.
- Prometheus dir. Ridley Scott
- Alien: Covenant dir. Ridley Scott
- Alien: Romulus dir. Fede Álvarez
Medium Mode
- Create a simple program to differentiate the original Alien vs. Predator films.
- The first four Alien films, Alien, Aliens, Alien 3, and Alien: Resurrection
- The first two Predator films, Predator, and Predator 2
- The two crossover films, Alien vs. Predator and *AVPR: Aliens vs Predator - Requiem”
Hard Mode
- Create a simple program to differentiate all Alien and Predator films covered in lecture.
Choose your own adventure
- You may, of course, consider other conceptual frameworks:
- Science fiction settings such as le Guin’s Earthsea, Asimov’s Foundation and Robot crossovers, Herbert’s Dune
- Cinematic universes such as Marvel
- Alien vs. Predator is an unusually high profile crossover, but I’m sure there are others of which I’m not aware.
Requirements
You should use the following:
Plus/Equals
- I found it very helpful in this lab to add many helpful tidbits together.
- “If you reply using capital letters, my program will break!”
- I used
=to give short nicknames to longer messages. - I used
+to combine them - usually before asking a question from the key. - Here is an example:
If/else Syntax
- Like
whilewhich we learned in the “Colab” lab, we can useifandelseto ask questions depending on some condition.- For example, we can ask if leaves are “smooth” or “lobed”.
ifleaves “smooth”, we can then ask if the leaves are evergreen.elsewe can ask if the lobes (or teeth) are bristle-tipped.- Far more easily, we ask yes or no questions.
- Here is an example:
if "yes" == input("Does the film feature Anakin Skywalker?"):
print("Prequel Trilogy")
else:
print("It's complicated")
Double equals? What’s that!
Nesting
- It is possible to place one
ifstatement inside another with indentation.- Term this “nesting”.
Your Task
- No write-up today, just try to get this working.