Tree Tree
AI 101
Trees and Keys
We return to the question of oaks 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:
Example
1. Leaves usually without teeth or lobes: 2
1. Leaves usually with teeth or lobes: 5
2. Leaves evergreen: 3
2. Leaves not evergreen: 4
3. Mature plant a large tree — Southern live oak Quercus virginiana
3. Mature plant a small shrub — Dwarf live oak Quercus minima
4. Leaf narrow, about 4-6 times as long as broad — Willow oak Quercus phellos
4. Leaf broad, about 2-3 times as long as broad — Shingle oak Quercus imbricaria
5. Lobes or teeth bristle-tipped: 6
5. Lobes or teeth rounded or blunt-pointed, no bristles: 7
6. Leaves mostly with 3 lobes — Blackjack oak Quercus marilandica
6. Leaves mostly with 7-9 lobes — Northern red oak Quercus rubra
7. Leaves with 5-9 deep lobes — White oak Quercus alba
7. Leaves with 21-27 shallow lobes — Swamp chestnut oak Quercus prinus
Visually
- You may have to zoom in…
- If you turn it upside down, it somewhat looks like a tree (hence the name).
Some oaks
- All are sourced from Wikipedia and appropriately licensed, with the links to the host page in the key.
Key
Click “Details” to expand
| Nickname | Common Name | Scientific Name |
|---|---|---|
| A | Blackjack oak | Quercus marilandica |
| B | Dwarf live oak | Quercus minima |
| C | Northern red oak | Quercus rubra |
URLs
- I have the best luck with prompting Gemini when I provide images as a URL.
- Here are the URLs for the leaf and tree of Oak A, the others are similar.
Requirements
| Letter | Common Name | Scientific Name |
|---|---|---|
| ‘a’ | Blackjack oak | Quercus marilandica |
| ‘b’ | Dwarf live oak | Quercus minima |
| ‘c’ | Northern red oak | Quercus rubra |
You should use the following:
Plus/Equals
- I found it very helpful in this lab to add many helpful tidbits to Gemini together.
- “Hey we are classifying trees!”
- “Hey here’s some images by URL!”
- “I’m a Python script, reply only yes/no with no capitals or punctuation!”
- 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 Gemini questions depending on some condition.- For example, we can ask if leaves are “smooth” or “lobed”.
ifGemini says “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:
Double equals? What’s that!
Nesting
- It is possible to place one
ifstatement inside another with indentation.- Term this “nesting”.
Your Task
- Try to get this to work such when you run a cell, it gives the name of a tree.
- No write-up today, just try to get this working.
- Big hint:
- The shape of the “Visually” graphic - of a question with branching questions below - is the same shape you should for with
ifstatements and indentation.
- The shape of the “Visually” graphic - of a question with branching questions below - is the same shape you should for with