Session 3 — Your First Prediction
Duration: 75 min · Format: live online · Ages: 12–15
Session goal: by the end, students can explain how a model learns a pattern, why we split data into training and test sets, and can build and run a real prediction with scikit-learn.
Before class — prep (5 min)
- Open Google Colab → New notebook, ready to screen-share. You'll build the predictor live. (scikit-learn is already installed in Colab — no setup needed.)
- Have the two diagrams below ready to share on screen (a model line predicting a new point and the train/test split).
- Have students reopen or start a fresh Colab notebook so they can code along.
Agenda
| Time | Segment |
|---|---|
| 0:00 | Hook — you already spot patterns (5 min) |
| 0:05 | Teach — a model learns the pattern, then predicts (13 min) |
| 0:18 | Teach — train, then test (no cheating) (13 min) |
| 0:31 | Activity — build a real predictor in Colab (27 min) |
| 0:58 | Check for understanding (10 min) |
| 1:08 | Wrap-up + homework (7 min) |
0:00 · Hook (5 min)
Ask the class and take a few answers (chat or unmute):
- "If someone studies more hours, do they usually score higher?"
- "How did you know that — did anyone give you a formula?"
Land the idea: their brain already sees the pattern. A model is just a program that finds that pattern in data and uses it to predict new cases. Tell them that today they'll make a computer predict — not magic, just patterns and math.
0:05 · Teach — A model learns the pattern, then predicts (13 min)
Explain: give a model some data points, and it finds the line — the pattern — that fits them. Then it can predict a new value by reading off that line.
Share this diagram and name the three parts:
- Dots = the data we already have (for example, size → price).
- Line = the pattern the model learned.
- ? = a prediction for a new input, read straight off the line.
Ask: "If all the dots sat perfectly on one straight line, how confident would the prediction be? What if they were scattered everywhere?" (Answer: a tight line means a strong, reliable pattern; a scattered cloud means a weak one.)
⚠ Watch for: students may think the model "memorises" the answers. It doesn't store the dots — it learns a general rule (the line) it can apply to inputs it has never seen.
0:18 · Teach — Train, then test — no cheating (13 min)
Explain: we never test a model on the same data it learned from — that's like handing it the exam answers first. We split the data into two parts.
Share this diagram and walk through the split:
- Training set (≈80%) — the model learns from this.
- Test set (≈20%) — kept hidden, used to check if it really learned.
- Accuracy = how often it's right on the test set.
Ask: "Why would testing on the training data give a misleadingly high score?" (Answer: the model has already seen those answers, so it can look perfect without having learned a general pattern.)
⚠ Watch for: students want to judge a model by how well it does on data it trained on. Stress that the test set — data it has never seen — is the only honest measure.
0:31 · Activity — Build a real predictor (27 min)
Have students open Google Colab and build a working predictor. Screen-share and build it line by line with them.
Type/run this together in Colab:
from sklearn.linear_model import LinearRegression
# our data: hours studied -> test score
hours = [[1], [2], [3], [4], [5]]
scores = [52, 60, 71, 79, 90]
model = LinearRegression()
model.fit(hours, scores) # 1) learn the pattern
prediction = model.predict([[6]]) # 2) predict for 6 hours
print("Predicted score:", prediction[0])
- Ask: "What score does it predict for 6 hours of study? Does that seem reasonable?"
- Have them change the data or predict for
[[8]]. Ask: "Does the answer still make sense?"
Circulate for the double-brackets confusion — hours is a list of lists ([[1], [2], …]), and predict also needs [[6]], not [6]. This is the error most students hit.
Explain: "You just trained a machine learning model in six lines. That .fit() step is the learning."
0:58 · Check for understanding (10 min)
Ask these aloud or drop them in the chat. Answer key (for you):
- Why do we keep a separate test set? → To check if the model really learned — not just memorised. Testing on the training data would be cheating.
- In the code, which line is the "learning" step? →
model.fit(hours, scores)—.fit()finds the pattern in the data. - What does higher accuracy mean? → The model is right more often on data it hasn't seen before.
1:08 · Wrap-up + homework (7 min)
- Ask one student to explain what
.fit()does in their own words. - Homework — Your own predictor: make a tiny dataset (e.g. minutes of practice → free throws made). Train the model, predict a new value, and write one sentence: is the prediction believable? Why or why not? Bring it to Session 4.
Teaching notes
- Correct this misconception: "the model memorises the data." It learns a general pattern it can apply to new, unseen inputs — which is exactly why the hidden test set matters.
- Common coding errors students hit: forgetting the double brackets —
hoursmust be[[1], [2], …]andpredictneeds[[6]]; mixing up which list is the input (hours) and which is the target (scores); calling.predict()before.fit(); readingpredictionas a plain number instead of a list (henceprediction[0]). - Fast finishers (extension): real data scientists compare models and measure them properly. Have them run this with a real dataset that has several rows (
X= features,y= target):
```python from sklearn.model_selection import train_test_split from sklearn.tree import DecisionTreeRegressor from sklearn.linear_model import LinearRegression from sklearn.metrics import mean_absolute_error
# X = features, y = target (use a real dataset with several rows) X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=1)
for model in [LinearRegression(), DecisionTreeRegressor()]: model.fit(X_train, y_train) preds = model.predict(X_test) print(type(model).name, "error:", mean_absolute_error(y_test, preds)) ```
Explain that lower error = better — ask which model wins on their data. Challenge them to change test_size or random_state and note whether the winner changes (their first real experiment).
- Low-tech fallback: if devices can't run Colab, plot the five (hours, scores) points on a shared grid, draw the best-fit line by hand, and read off the prediction for 6 hours — then show that scikit-learn does exactly this, only with math.
Vocabulary
| Term | Meaning |
|---|---|
| Model | A program that learns a pattern to predict |
| Train / Fit | Teaching the model with data (.fit) |
| Test set | Hidden data used to check the model |
| Feature | An input used to predict (e.g. hours) |
| Accuracy | How often the model is right |
Resources
- Kaggle — Intro to Machine Learning — free, hands-on, a perfect next step.
- scikit-learn — getting started — the official guide.
- Google Colab — where you run it all.
Next session
Session 4 — What AI Can (and Can't) Do: before going further, the most important lesson of the unit — using this power responsibly and fairly.