Tree Tree

AI 101

Trees and Keys

We return to the question of oaks with:

  1. More understanding of Colab, and…
  2. 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

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).

OakKey Start Leaves are smooth with no teeth or lobes? Evergreen Laves evergreen? Start->Evergreen True Bristles Lobes/teeth bristle-tipped? Start->Bristles False GrowthHabit Large Tree (not shrub)? Evergreen->GrowthHabit True LeafShape Leaves more than 3x long as wide Evergreen->LeafShape False LiveOak Southern live oak GrowthHabit->LiveOak True DwarfOak Dwarf live oak GrowthHabit->DwarfOak False WillowOak Willow oak LeafShape->WillowOak True ShingleOak Shingle oak LeafShape->ShingleOak False LobeCount6 3 or fewer lobes? Bristles->LobeCount6 True LobeCount7 9 or fewer lobes? Bristles->LobeCount7 False BlackjackOak Blackjack oak LobeCount6->BlackjackOak True RedOak Northern red oak LobeCount6->RedOak False WhiteOak White oak LobeCount7->WhiteOak True SwampOak Swamp chestnut oak LobeCount7->SwampOak False

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

tree_letter = "a"
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:
from google.colab import ai
prefix = "I'm a Colab notebook, and I cannot read! Reply only yes/no with no capitals or punctuation!"
question = "Is four an even number"
answer = ai.generate_text(prefix + question)
print(answer)

If/else Syntax

  • Like while which we learned in the “Colab” lab, we can use if and else to ask Gemini questions depending on some condition.
    • For example, we can ask if leaves are “smooth” or “lobed”.
    • if Gemini says “smooth”, we can then ask if the leaves are evergreen.
    • else we can ask if the lobes (or teeth) are bristle-tipped.
    • Far more easily, we ask yes or no questions.
  • Here is an example:
if answer == "yes":
  print("Four is an even number")
else:
  print("Four is not an even number")
Double equals? What’s that!

In Colab, both = and == mean something.

  1. I call = “single equals assignment”. It assigns a nickname to something longer or more complicated. It gets its own line.
  2. I call == “double equals equality”. It checks to see if two things are equal, usually with an if.
if 1 == 1:
    print("Hi!")

Nesting

  • It is possible to place one if statement inside another with indentation.
    • Term this “nesting”.
even = ai.generate_text(prefix + "Is four an even number")
positive = ai.generate_text(prefix + "Is four a positive number")

if even == "yes":
  if positive == "yes":
    print("Even positive number.")
  else:
    print("Even negative number.")
else:
  print("Odd number.")

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 if statements and indentation.