Classification combines categorical labels by voting. Regression combines continuous targets: uniform mode takes their arithmetic mean, while distance weighting takes a weighted mean.
Misread to avoid: The colored surface is a field of local averages, not a fitted straight line or evidence that nearby targets cause the query value.
Fidelity boundary: this two-feature teaching view scans stored points directly. Production regression still needs validation, scaling, missing-value handling, and an appropriate neighbor index.
🧭 Guided challenge: predict before reveal
Choose a query point, select exactly k training points you predict will count as nearest, and predict the class. Lock the prediction before revealing the model's selected neighbors and vote.
🔢 k-fold cross-validation (compare candidate k values)
Splits the current sample into f folds. For each candidate k, it trains on f−1 folds and validates on the remaining fold, then averages across rotations. The highest score is evidence for this sample and fold scheme, not a universally correct k; stability, class balance, the metric, scaling, and domain costs still matter.
🎯 Try these scenarios first
Pick a scenario, predict what should happen, then apply it and compare the result with your prediction.
Scenario 2: Small and large k make different errors
Scenario 3: The distance rule changes the neighborhood
Scenario 4: Feature scale can distort distance
Scenario 5: Distance weighting changes a noisy vote
✨ 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
No state captured yet. Run or adjust the applet first.
📚 Lesson tour (5 steps)
-
📝 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 the closeness rule to Manhattan. Which statement is mathematically accurate?
🧪 Quick Assign · QA-KNN-01 · 10–15 min
Compare classification voting with regression averaging while keeping the same k, metric, weighting, and selected neighbors.
♿ 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.