5
1.0× < 1 shrinks X (Y dominates). > 1 stretches X (X dominates). Watch the boundary tilt.
Class A Class B Hover anywhere to see how k neighbors vote.
🔢 k-fold cross-validation (find the best k)

Splits the training points into f equal folds. For each k in 1..30, trains on f−1 folds and validates on the held-out fold; averages accuracy across all f rotations. The k with highest CV accuracy is the right pick: NOT the k that fits the training data best (that's always k=1).

5 20
(click "Run CV": needs at least 10 training points)
✨ Featured comparison
Featured comparison

Move the query point near the boundary and compare k=1 with a larger k. The nearest neighbor can be vivid and wrong.

Change k after placing the query point near mixed classes, then compare the vote explanation.

🧭 Visual explanation

Live state to watch
No state captured yet. Run or adjust the applet first.
Misread to avoid

📚 Lesson tour (5 steps)
Step 1/4: -

-

📝 Worksheet (3 questions)

Q1. Load two blobs, k=1. Add a test point right in the middle, between the blobs. Which class does k=1 assign?

Q2. Same dataset, switch to k=25. Compared to k=1, the decision boundary becomes:

Q3. Switch distance metric to Manhattan. The boundaries between classes are now made of:

🧪 Student response packet

Adjust k, metric, and weighting, then explain how local neighbors reshape the decision boundary.

State snapshot appears here.
♿ Text and keyboard support

Text and keyboard support

Keyboard path

  • Use Tab and Shift+Tab to move through controls.
  • Use Enter or Space on buttons, and arrow keys on sliders or select controls.
  • The visual region is focusable and described by the state summary below.

Text state summary

Reduced motion and non-visual support

Reduced-motion settings are honored where possible. The current state is also available as text, so the main result does not depend only on color, animation, or spatial position.

Accessibility note: this layer gives a text equivalent for the applet state. It does not replace a full human screen-reader audit.