AI summary by TwinMind
StatQuest: K-nearest neighbors, Clearly Explained
StatQuest with Josh Starmer
5m 30s
Introduction & Overview
- Stack Quest educational video from UNC Chapel Hill genetics department
- Topic: K-nearest neighbors (KNN) algorithm for data classification
- Use case: Classifying cell types using existing labeled data
- Simple method to determine unknown cell type based on similarity to known cells
Algorithm Steps & Methodology
- Step 1: Start with dataset of known categories
- Example: Different cell types from intestinal tumor
- Cluster data using PCA (Principal Component Analysis)
- Step 2: Add new cell with unknown category to plot
- Cell from another tumor where cells not properly sorted
- Goal: Classify new cell by finding most similar cell type
- Step 3: Classify by examining nearest annotated cells (neighbors)
K Value Selection & Voting System
- K=1: Use only nearest neighbor for classification
- Example: Nearest neighbor is green → classify as green cell type
- K=11: Use 11 nearest neighbors
- Example: All 11 closest cells are green → classify as green
- Voting mechanism: When cell between multiple categories
- Count votes from K nearest neighbors
- Example: 7 red, 3 orange, 1 green neighbors → classify as red (most votes)
Heat Map Application
- Same principle applies to hierarchical clustering heat maps
- K=1: Look at single nearest cell (light blue) → classify as light blue
- K=5: Five nearest cells all light blue → classify as light blue
- Edge cases: Cell near cluster boundary with K=11
- 7 light blue neighbors, 4 light green → classify as light blue
Tie-Breaking & Edge Cases
- Use odd K values to avoid ties
- If tied vote occurs: flip coin or don't assign category
- Cell positioned exactly between two categories requires careful consideration
Machine Learning Terminology
- Training data: Initial clustering data with known categories in advance
- Standard data mining/machine learning classification approach
K Value Selection Best Practices
- No physical/biological method to determine optimal K
- Testing approach: Pretend part of training data is unknown
- Categorize using KNN algorithm
- Assess how well new categories match known categories
- Low K values (K=1, K=2):
- Can be noisy
- Subject to outlier effects
- Large K values:
- Smooth over variations
- Risk: Categories with few samples always outvoted by larger categories
- Must try multiple K values before settling on optimal choice
