Nearest Neighbor Baseline
What you'll learn: How to implement the simplest few-shot classification approach by finding the nearest support example in embedding space.
The Core Idea
The Nearest Neighbor Baseline is the most straightforward few-shot learning method. Once you've embedded your support set examples (the labeled examples you have) into a learned embedding space, you classify a new query example by finding which support example it's closest to and assigning that label.
Think of it like asking "Which training example does this new thing look most like?" If your new query image resembles a support cat more than a support dog, label it as cat.
How It Works
Given an N-way K-shot episode:
- Embed everything: Pass all support examples and your query through your embedding network to get feature vectors
- Compute distances: Calculate the distance (typically Euclidean or cosine) between your query embedding and each support embedding
- Assign label: Find the nearest support example and assign its label to the query
This is called a "baseline" because it requires no additional training beyond learning a good embedding space. There's no learned classifier on top—just pure nearest neighbor lookup.
Why It Matters
Despite its simplicity, this baseline is surprisingly effective and serves as the foundation for more sophisticated meta-learning methods. It validates whether your embedding space has captured meaningful similarities. If random embeddings work as well as learned ones, you know your embedding isn't helping.
Key Takeaway: The Nearest Neighbor Baseline classifies few-shot queries by finding the closest support example in embedding space—simple, interpretable, and a crucial performance benchmark for any few-shot learning system.