🦁 Digital Camp × London Zoo
Introduction to Python,
Data Analysis &
Machine Learning
Trinity Stenhouse
PhD Physicist, CTO & AI Architect
Part 1 of 2 · ~30 minutes
What We're Doing Today
Python & Colab refresher
🐍
Variables, functions, how to run code in the browser
Essential libraries
📦
NumPy, Pandas, Matplotlib — the data scientist's toolkit
Exploring data
📊
Load a real dataset, spot patterns, make charts
What is Machine Learning?
🤖
Teaching a computer to learn rules from examples
Your first ML model
🌳
Decision tree to classify London Zoo animals
Google Colab — Your Python Environment
📝 Cells
Write code or text in separate blocks
What is Google Colab?
A free coding environment that runs in your browser.
▶ Run
No installation needed — Python, libraries, and even a GPU
are all available instantly. Shift+Enter to run a cell
You save your work to Google Drive automatically.
⚡ GPU
Runtime → Change runtime type → T4 GPU
💡 Tip: If a cell produces an error, read it from the bottom up — the last line tells you what went wrong.
Python Refresher — The Essentials
Core building blocks: Things to remember:
# Variables Indentation matters
name = "London Zoo"
year = 1828 Python uses spaces (not brackets) to define blocks — always 4
spaces
# Lists
animals = ["lion", "giraffe"]
[Link]("penguin") Everything is an object
# Loops Numbers, text, lists — they all have built-in methods you can call
for animal in animals:
print(animal)
Import libraries
# Functions
def classify(features): import pandas as pd — load powerful tools in one line
return "mammal"
Comments with #
Explain your code to your future self (and teammates)
The Data Scientist's Toolkit
np NumPy pd Pandas
Fast numerical arrays and maths. Loads and manipulates tables of data.
Every ML library is built on top of NumPy. A DataFrame is like a spreadsheet inside Python — rows are samples,
columns are features.
Think of it as a supercharged list that can do maths on thousands of
numbers at once.
[Link]([1, 2, 3]) * 2 df['legs'].mean()
→ [2, 4, 6] → 3.8
plt Matplotlib sklearn Scikit-learn
Plotting and visualisation. Machine learning models.
Turn numbers into charts — bar plots, scatter plots, heatmaps — all in a Decision trees, random forests, SVMs — one consistent API for training,
few lines. predicting, and evaluating.
[Link](names, counts) [Link](X_train, y_train)
Exploring Data with Pandas DataFrames
import pandas as pd Rows = samples
# Load data Each row is one animal (one observation in our data)
df = pd.read_csv('[Link]')
# First look
[Link]() # first 5 rows Columns = features
[Link] # (101, 18)
[Link] # column types Each column is a characteristic: hair, legs, eggs, class...
# Select a column
df['class_name']
[Link]()
# Filter rows Your first command on any new dataset — always look before you
df[df['milk'] == 1] # only mammals leap
# Count values
df['class_name'].value_counts() [Link]()
# Average legs per class Summary statistics: mean, min, max for every column at once
[Link]('class_name')['legs'].mean()
🔑 The golden rule: explore before you model. Always
understand your data first.
Visualisation — Turning Numbers Into Insight
"A chart you can glance at beats a table you have to read."
Bar chart [Link]() Line chart [Link]()
Compare counts or averages across categories Show how something changes over time or across values
Scatter plot [Link]() Heatmap [Link]()
Find relationships between two continuous variables Show patterns in a table of values — great for correlations
What Is Machine Learning?
❌ Traditional Programming ✅ Machine Learning
Rules + Data → Output Data + Outputs → Rules
You write: You show it examples:
if feathers == 1: [hair=1, milk=1, eggs=0] → Mammal
class = 'Bird' [feathers=1, airborne=1] → Bird
elif milk == 1: [fins=1, aquatic=1] → Fish
class = 'Mammal' ...
elif fins == 1:
class = 'Fish' The algorithm figures out the rules itself.
... Show it enough examples and it learns to
classify things it's never seen.
This gets complicated fast — and breaks
when you see something new.
Three Flavours of Machine Learning
🏷 🔍 🎮
Supervised Learning Unsupervised Learning Reinforcement Learning
What we're doing today No labels needed Learn by doing
You give the model labelled examples. You give the model data with no labels. An agent learns by taking actions and receiving
rewards or penalties.
Input: animal features The model finds hidden structure — natural
Label: animal class (Mammal, Bird...) groupings or patterns — on its own. No dataset needed — the model learns through
trial and error.
Model learns to predict the label for new,
unseen inputs.
Examples: Examples: Examples:
Email spam filter Customer segmentation Game-playing AI
Medical diagnosis Anomaly detection Robot navigation
Animal classification Topic modelling in text Recommendation systems
The Golden Rule: Train/Test Split
📚 Think of it like revising for an exam: you study past papers (training), but your actual grade comes from questions
you've never seen before (test).
Training set (80%) Test set (20%)
All data
● Never let the model see test data during training
If you train on test data, your accuracy score is meaningless — you're marking your own homework.
● Always use random_state=42
Fixes the random split so you (and your teammates) get identical results every time.
● Accuracy on test set is what matters
High training accuracy but low test accuracy = overfitting (the model memorised, not learned).
Decision Trees — Learning from Questions
NO NO
Has feathers? Produces milk? ... and so on
YES YES
🐦 Bird 🦁 Mammal
The computer writes these rules for you
It tests every possible question at every node and picks the one that best separates the classes.
Metric: Gini impurity
Measures how mixed the classes are after a split. The algorithm picks the split that makes each branch as pure as possible.
max_depth controls complexity
A deeper tree can ask more questions — but too deep and it memorises noise instead of patterns.
Did It Work? Evaluating Your Model
Accuracy alone can be misleading. Always look at the full picture.
Accuracy correct / total Confusion Matrix
Percentage of predictions that were right. Simple, but misleading if A grid showing what the model predicted vs what was actually
classes are unbalanced (e.g. 90 mammals, 1 frog). correct. Off-diagonal cells are mistakes — they tell you which
classes get confused with each other.
Precision TP / (TP + FP) Recall TP / (TP + FN)
Of everything the model labelled 'Bird', how many were actually Of all the real birds in the dataset, how many did the model
birds? actually find?
The Most Important Skill: Finding Answers
My goal today is not to teach you everything about ML.
It's to show you what real analysis looks like — and equip you to find the answers you don't have yet.
Try to solve it yourself
1
Read the error message. Google the exact message. Try changing one thing at a time.
Load your notes into an AI agent
2
Copy your question + the relevant code into Claude or ChatGPT. Ask it to explain what's wrong and why.
Query the specific notebook cell
3
"In cell 7 of my notebook, I get this error: [paste error]. The cell does X. What's wrong?"
Ask a person
4
Your instructors exist for this. But try steps 1–3 first — you'll learn more from the attempt.
Time to code! 🎉
Open London_Zoo_ML_Intro in Google Colab
► Part 1–2 · Load and explore the Zoo dataset
► Part 3 · Understand train/test split
► Part 4 · Train a decision tree
► Part 5–6 · Evaluate with confusion matrix and feature importance
► Part 7 · Predict your own mystery animal!
Don't worry about finishing — focus on understanding. The reflection questions matter more than the code.