K - Nearest Neighbors
K - Nearest Neighbors
K-Nearest Neighbors
Key Idea:
Just store all training examples <xi, f(xi)>
2
INSTANCE BASED LEARNING
K-Nearest Neighbors
Classification Algorithm:
* Given query instance xq
* Locate nearest training example xn
* Estimate
3
Simple Analogy..
KNN – Different names
• K-Nearest Neighbors
• Memory-Based Reasoning
• Example-Based Reasoning
• Instance-Based Learning
• Lazy Learning
What is KNN?
• A powerful classification algorithm used in pattern
recognition.
• Each of the training data consists of a set of vectors and a class label
associated with each vector.
17
INSTANCE BASED LEARNING
Terminology
18
KNN Feature Weighting
• Scale each feature by its importance for
classification
• Can use our prior knowledge about which
features are more important
• Can learn the weights wk using cross‐
validation
Feature Normalization
Nominal/Categorical Data
• Distance works naturally with numerical
attributes.
• Binary value categorical data attributes can be
regarded as 1 or 0.
KNN Classification
KNN Classification – Distance
KNN Classification – Standardized Distance
Strengths of KNN
• Very simple and intuitive.