KNN Visualizer
About This MicroSim
This MicroSim demonstrates how the K-nearest neighbors algorithm finds similar items in embedding space by visualizing distance calculations and neighbor selection.
Iframe Embed Code
1 2 | |
Description
Understanding KNN
| K Value | Effect | Use Case |
|---|---|---|
| K=1 | Single most similar item | Exact match finding |
| K=3-5 | Small neighborhood | Recommendations |
| K=10+ | Large neighborhood | Exploration |
How to Use
- Click any point to select it as the query
- Adjust K with the slider (1-15)
- Toggle distance circles to see the neighborhood boundary
- Toggle connection lines to see ranked connections
- View the results panel for similarity scores and statistics
- Click Random to explore different query points
Visual Elements
- Colored points: MicroSims grouped by subject
- Distance circles: Concentric rings showing distance from query
- Connection lines: Ranked connections to neighbors
- Dashed boundary: The "neighborhood" containing K items
Learning Objectives
After using this MicroSim, students will be able to:
- Differentiate between query results with different K values
- Analyze how K affects the composition of neighbors
- Explain the trade-off between precision and coverage
Lesson Plan
Introduction (5 minutes)
- Explain KNN as "find the K most similar items"
- Discuss applications: recommendations, classification
- Introduce the visualization
K Value Exploration (15 minutes)
- Start with K=1, observe single nearest neighbor
- Increase to K=3, then K=5, then K=10
- Notice how neighbors change with different K values
- Observe statistics: average similarity, range
Cross-Subject Analysis (10 minutes)
- Select a Physics item, examine neighbors
- Are all neighbors Physics? Why or why not?
- Select an item near cluster boundaries
- Discuss "boundary" items and their neighbors
Discussion (5 minutes)
- Why might you choose K=3 vs K=10?
- How does K affect accuracy vs. coverage?
- What happens with very large K?