K-Nearest Neighbors

K-Nearest Neighbors Lab

Interactive decision regions, neighbor inspection और weighted voting के साथ instance-based classification।

K-NN global model parameters नहीं सीखता। यह feature space में nearby training points के labels से prediction करता है।

Query point x के लिए सबसे नज़दीकी K samples चुनें और उनकी labels को majority vote (या weighted vote) से aggregate करें।

$$\hat{y}(x)=\arg\max_c \sum_{i\in \mathcal{N}_K(x)} w_i\,\mathbf{1}(y_i=c)$$

  • छोटा K: boundary ज्यादा flexible, local noise के प्रति संवेदनशील।
  • बड़ा K: boundary smoother, variance कम, bias ज्यादा हो सकता है।
  • Weighted voting (w=1/d) बहुत पास वाले neighbors को ज्यादा महत्व देता है।

K-NN distance पर निर्भर है, इसलिए feature scaling real datasets में बहुत महत्वपूर्ण है। Standardization आमतौर पर reliability बढ़ाता है।

Prediction cost dataset size के साथ बढ़ता है क्योंकि inference पर कई distances compute करनी होती हैं।

Validation से K चुनें और noisy या overlapping class distributions पर robustness जांचें।

  1. Demo distribution लोड करें (vertical, XOR, concentric, overlap, random)।
  2. K बदलें और weighted voting toggle कर boundary तुलना करें।
  3. Test Mode ऑन करें और nearest neighbors व class probability देखें।
  4. Region density बढ़ाकर finer boundaries देखें, फिर तेज rendering के लिए घटाएं।

Training samples जोड़ने के लिए क्लिक करें। Test Mode में query point classify करने और neighbors देखने के लिए क्लिक करें।

Model Info
Points: 0 A | 0 B
Last Test P(B): -
Nearest Neighbors