- Introduced by
- Settles, B. (active learning framework); Fix & Hodges (KNN base)
- Year
- 1951–2010
- Type
- Active learning with KNN base learner
- Family
- Machine learning
What does it do?
Active learning with K-nearest neighbors pairs the instance-based prediction of KNN with an iterative query strategy.
At each round, the strategy selects the unlabeled examples the current model is least certain about and sends them for annotation. Labeling effort therefore concentrates where neighborhood votes are most evenly split, which is typically near the decision boundary.
The intuition behind the method
KNN classifies a point by looking at its k nearest labeled neighbors and taking a majority vote. When those neighbors are almost evenly split between classes, the model is genuinely uncertain — and that uncertainty pinpoints which unlabeled example would be most worth labeling. Active learning exploits this signal: at each iteration, the algorithm finds the unlabeled point whose neighborhood is most evenly divided, asks an oracle to label it, adds it to the labeled pool, and repeats. The result is that labeling effort concentrates near decision boundaries, where new labels teach the most.
History
The k-nearest neighbors classifier is a long-established nonparametric method in pattern recognition. Active learning as a framework was surveyed by Burr Settles (2010), who covers pool-based uncertainty sampling, query-by-committee and density-weighted strategies. Combining active learning with semi-supervised learning has also been studied; Zhu, Lafferty and Ghahramani (2003) use Gaussian fields and harmonic functions for this purpose, a graph-based formulation that differs from the vote-entropy criterion described here.
When to use it
Use active learning with KNN when labeled data are scarce or costly to obtain, unlabeled instances are plentiful, the feature space is of moderate dimensionality, and the decision boundary is expected to be locally smooth. It is especially practical in early-stage classification projects where labeling must be rationed. Avoid it when the dataset is very high-dimensional (KNN distance metrics degrade in high dimensions, the curse of dimensionality), when the labeled pool is already large (passive KNN suffices), when low-latency prediction is required at scale (KNN prediction is O(n) in the labeled set), or when the label budget is so small that neighborhood estimates are unreliable.
Limitations and considerations
- Prediction cost scales linearly with labeled set size, making inference slow as the pool grows through iterations.
- Distance-based uncertainty degrades sharply in high-dimensional spaces due to the curse of dimensionality.
- The vote-split uncertainty depends on k and the distance metric; poor choices produce unreliable query scores.
- All labeled points are stored in memory, so memory use grows with the labeling budget.
- KNN has no learned decision function, so the query strategy cannot make the model capture structure that the distance metric does not represent.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- Non-parametric: the decision rule is defined by the labeled neighbors and the chosen distance metric, with no fitted parametric form.
- Uncertainty is read directly from the neighbor vote split, so the query score can be inspected by hand for any candidate instance.
- Lazy learning means adding a labeled point updates the model immediately, with no retraining step per iteration.
- Because queries are taken where neighbors disagree, labels accumulate along the boundary, where KNN predictions are least stable.
Applications
- Medical record or image annotation where expert labeling time is limited and decision boundaries are locally smooth, with image features reduced to a moderate dimensionality before distances are computed.
- Text or document classification with small labeled corpora and abundant unlabeled documents, using low-dimensional document embeddings (for example, after dimensionality reduction) rather than raw high-dimensional representations.
- Sensor and industrial fault detection tasks where only a fraction of events can be manually verified.
- Ecological surveys where field confirmation of species labels is expensive and locally clustered.
- Early-stage prototype classifiers before switching to a higher-capacity model once sufficient labels are collected.
How it works
How it works
A small initial set of labeled instances is assembled to seed the process, together with a larger pool of unlabeled instances. Stratified random selection is recommended so that every class is represented in the seed set, since KNN needs labeled neighbors of each class to form meaningful neighborhoods before the active loop begins.
A KNN classifier is fitted on the current labeled set using a chosen k and distance metric (commonly Euclidean or cosine). Because KNN is lazy and stores all training points, fitting is instantaneous, but prediction cost scales linearly with the labeled set size, a relevant consideration as the pool grows through iterations.
Each unlabeled instance is scored by an informativeness criterion. The formula given for this step uses entropy: H(y-hat | x) is computed over the class proportions among the k nearest labeled neighbors, and the instance with the highest entropy is queried, x* = argmax H(y-hat | x). The entropy criterion requires k of at least 2, because with k = 1 every vote is unanimous. Ties between candidates with the same maximal score are broken at random; a fixed rule such as list order should be avoided because it can bias queries toward particular records. The procedure described here queries one instance per round; batch selection, which queries several instances at once, is a separate extension. Margin sampling, which uses the gap between the vote shares of the two leading classes, is a closely related criterion. For two-class problems the two criteria rank candidates identically, because the entropy of a two-class vote split falls monotonically as the gap between the two shares widens. With three or more classes they can differ: entropy reflects the full vote distribution, whereas margin considers only the two leading shares.
Formula
x^* = \arg\max_{x \in U} H(\hat{y} \mid x)The queried instance is sent to an oracle, such as a human annotator or an automated labeling mechanism, for its true label. The label is added to the training set and the instance is removed from the unlabeled pool. Annotator reliability should be monitored, because mislabeled points near a boundary can distort the votes of later neighborhoods.
Because KNN is a lazy learner, no explicit retraining is needed; the expanded labeled set immediately constitutes the new model. The query-score-label cycle repeats until the labeling budget is exhausted, a validation accuracy threshold is met, or a maximum iteration count is reached. Final performance is reported on an independent held-out test set.
Common pitfalls
- Failing to normalise features before computing distances, which lets high-magnitude features dominate the neighborhood.
- Using the test set to guide or evaluate query selection, which constitutes data leakage.
- Setting k = 1, under which every neighborhood vote is unanimous and the entropy query score is always zero, so the criterion cannot rank candidates. Use k of at least 2, preferably an odd value in the 5 to 15 range.
- Ignoring class imbalance in the seed set, which biases early queries toward majority-class boundaries.
- Reporting active-learning accuracy without stating the number of labels used, which makes it impossible to compare with a fully supervised baseline.
Frequently asked questions
Why use KNN rather than a more powerful model as the active learning base?
KNN's vote-split uncertainty is cheap to compute and requires no retraining: adding a new labeled point immediately updates the model. This makes it attractive when per-iteration computational cost matters. If maximum accuracy on a fixed label budget is the priority, other base learners, such as ensembles, may perform better on some problems, and the comparison should be made on the target data.
How do I choose k for active learning?
A common starting range is k = 5 to 15. This is a rough heuristic that depends on dataset size and the number of classes, so it should be validated on the target data. The entropy criterion needs k of at least 2, since with k = 1 every vote is unanimous and the score is always zero. Odd values avoid ties in two-class problems. Smaller k values produce noisier uncertainty estimates; larger k values smooth the boundary but may miss fine-grained ambiguity. Cross-validate k on the initial labeled seed set and adjust as the labeled pool grows.
Does feature scaling matter?
Yes, critically. KNN distance is dominated by high-magnitude features if features are not normalised. Always apply min-max scaling or z-score standardisation before computing distances and uncertainty scores.
How many initial labeled examples are needed?
At minimum, one or two labeled instances per class are required so that KNN can form neighborhoods for all classes. In practice, 5–20 labeled instances are a rough starting heuristic; the appropriate size depends on dataset size and the number of classes and should be checked on the target data. Fewer labeled instances risk degenerate neighborhoods that produce uninformative early queries.
When should I stop the active loop?
Set a labeling budget in advance, or monitor validation accuracy and stop when improvement per new label falls below a meaningful threshold. Never use the test set as a stopping signal, as this leaks information into the query process.
Related methods
Sources
Settles, B. (2010). Active Learning Literature Survey. Computer Sciences Technical Report 1648, University of Wisconsin-Madison.
Open publication referenceZhu, X., Lafferty, J., & Ghahramani, Z. (2003). Combining active learning and semi-supervised learning using Gaussian fields and harmonic functions. Proceedings of the ICML 2003 Workshop on the Continuum from Labeled to Unlabeled Data, 58–65.
Open publication reference