Technology and Computer Science Computer Science

Teaching a Computer with Examples: A Paper Nearest-Neighbor Classifier

Students act as a simple machine-learning program that labels messages by comparing them with labeled examples, then discuss what can go wrong.

Grades 9-1250 minutesSP-CS-016

THE GOAL

What students will learn

Students will classify new items by finding the nearest labeled examples, compare a one-neighbor method with a three-neighbor vote, and explain how training data shapes what an AI system does.

BEFORE THE BELL

Get ready

Copy the 2-page worksheet (one per student). Write the distance rule from Before Class on the board.

KEEP THE PLAN CLOSE

Your teacher guide

Teacher directions only. Student worksheets and the answer key are in the complete PDF.

SubstitutePlans.com
Technology and Computer Science · Computer Science
SP-CS-016 · Free to print and use in your classroom · substituteplans.com
Page 2
Teaching a Computer with Examples: A Paper
Nearest-Neighbor Classifier
Technology and Computer Science · Computer Science · Grades 9-12 · 50 minutes
Time needed
50 minutes (one class period)
Prep
Copy the 2-page worksheet (one per student). Write the distance rule from Before Class on the
board.
Technology
None.
Student
independence
Medium. Students follow a written method, then discuss the limits of AI with a partner.
Copies to make
One 2-page worksheet per student
Materials
Pencils, Worksheet, Whiteboard or chalkboard
Goal for today: Students will classify new items by finding the nearest labeled examples, compare a one-neighbor
method with a three-neighbor vote, and explain how training data shapes what an AI system does.
Before the bell
☐ Copy the worksheet, one per student (2 pages).
☐ On the board write the distance rule: distance = (gap in exclamation marks) + (gap in capital-letter words),
ignoring minus signs. Example: from (7, 5) to (3, 4) is 4 + 1 = 5.
☐ Keep the answer key on your desk. The tables are already worked out for you there.
☐ Tell students the program does not understand language; it only compares counts.
Say this to start
Good morning! A lot of what people call artificial intelligence is a computer learning from examples. Today you will play
the part of one very simple learning program. It has a list of messages that humans have already labeled as spam or
normal, and your job is to label new messages by finding which old messages they are most similar to. Then we will
talk about what could go wrong.

SubstitutePlans.com
Technology and Computer Science · Computer Science
SP-CS-016 · Free to print and use in your classroom · substituteplans.com
Page 3
Run of show
Minutes
What you do
What students do
0–5
Take attendance. Hand out the worksheet and ask
students to read the opening box.
Read how the program works.
5–12
Go over the distance rule on the board. Work the example
aloud: from message A at (7, 5) to the new message at (3,
4), the gap is 4 across and 1 up, so the distance is 5. Ask:
“What is the distance from D (5, 4) to the new message?”
(2).
Follow the example and answer the
question.
12–22
Tell students to fill in the distance column of the table for
the new message N3 (Part A).
Calculate nine distances.
22–34
Tell students to answer questions 1–7 in Part B. Remind
them to use the distance table for N3 and the rule on the
board for the other messages.
Label new messages using one neighbor
and three neighbors.
34–44
Tell students to finish questions 8–14. Partners may talk
about questions 13 and 14 before writing.
Answer the reasoning questions.
44–48
Read answers to the table and questions 1–7 from the key.
Students check their work.
Mark and correct answers.
48–50
Collect all worksheets.
Hand in the worksheet.
If things go wrong
• If students ask whether this is real AI, say yes: the idea is a real method called nearest neighbor. Real
systems use many more examples and many more features.
• If students get different distances, have them recompute one pair together, writing the gaps first and then
adding them.
• If students find a tie in distance, both tied messages are in the vote when they share a label. The key has
every tie worked out.
• If a student argues about spam, remind them the computer only follows the numbers and labels it was given.
Early finishers
• Make up a new message with its own counts of exclamation marks and capital-letter words, then label it using
the nearest neighbor.
• Invent two other features a program could count to spot spam, and explain why each might be helpful or
misleading.
• Explain in two sentences how a program like this could be unfair to someone who writes in an excited style.
Support and challenge
• Support: Let students fill in only the first four rows of the distance table (A to D) and answer questions 1, 2, 4,
5 and 9.
• Challenge: Ask students to find a new message (x, y) for which the one-neighbor method and the
three-neighbor vote give different answers, and show why.

SubstitutePlans.com
Technology and Computer Science · Computer Science
SP-CS-016 · Free to print and use in your classroom · substituteplans.com
Page 4
Notes for the teacher (you fill this in)
Jot a few lines before you leave. A full Daily Sub Report is in the free Sub Survival Kit at SubstitutePlans.com.
How far the class got / what to pick up next:
Students who were especially helpful:
Anything the teacher should know:

READY WHEN YOU ARE

Take the plan with you.

Teacher copy — includes the answer key.

The complete PDF includes welcome pages, substitute directions, student worksheets, and answers. Give students only the worksheet pages. Check the page labels before you print or share.

Download complete teacher PDF

Opens the PDF in a new tab. Use its print controls to select the student pages you need.

Download teacher phone guide

A readable guide that opens offline in your browser. Student worksheets and answers are not included.

Free lesson · SP-CS-006Guide ↓PDF ↓