Log inStart free
LESSON 4.18 · 6 STAGES · 3 CONTROLS · 3 CHECKSPRO · PREVIEW

K-nearest neighbors

Watch the K nearest known fruits vote on the label of a new fruit.


Pro lesson. Stage 1 is free to watch. Pro opens all 6 stages, 3 controls and 3 checks, in this lesson and every other.

Go Pro · $8.25/mo
EXPLAINER · 4.18 · NEIGHBOR BAY16 FRUITS · 9 APPLES · 7 PEARS
01
Stage 1 of 6 · Known fruits
Training KNN only stores the 16 known fruits. The new fruit q has no label yet.
Explain it simply

Each mark is a fruit you already know. Its spot shows its width and height. Its shape shows its label: a circle for an apple, a triangle for a pear. One pear is odd: it's wide and short, so it sits with the apples. KNN learns nothing ahead of time. It keeps the list and waits.

16 known fruits on a plane of width and height in cm: 9 apples and 7 pears. The new fruit q is at (7.5, 9.1).

known fruit (circle apple, triangle pear), new fruit qK, its circle, vote weightvote and predictionleave-one-out misstraining error
known fruits456789101156789101112width (cm)height (cm)odd pearqknown fruits456789101156789101112width (cm)height (cm)odd pearq
Toy: 16 known fruits (9 apples, 7 pears) · 2 features in cm · 1 new fruit · a 28 × 28 grid
STAGE 1 / 6
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
D={(xi, yi)}i=116,q=(q1,q2)\mathcal{D} = \{(\sy{x}{data}{\mathbf{x}_i},\ \sy{y}{data}{y_i})\}_{i=1}^{16},\quad \sy{q}{data}{\mathbf{q}} = (q_1, q_2)
q=(7.5,9.1) cm;9 apples, 7 pears\mathbf{q} = (7.5, 9.1)\ \text{cm};\quad 9\ \text{apples},\ 7\ \text{pears}

The data is 16 fruits, each a point with a label.

Common mix-ups

MYTHK = 1 is best, because it gets every known fruit right.

The fix, and 1 more mix-up with the diagram to show them, come with Pro.

Predict, then reveal
3 CHECKS · PRO
Q01By the odd pear, what does K = 1 predict?

Make your guess, then test it in the diagram. All 3 checks come with Pro.

PRO LESSON · YOU WATCHED STAGE 1 OF 6
Unlock the full explainer
  • 5 more stages and 3 live controls
  • 2 mix-up cards and 3 predict-then-reveal checks
  • Watch it as a narrated video, in three voices
  • Every Pro lesson and capstone · 656 in total

$99 a year, or $15 a month. Cancel any time.