Curious Minds

Clear answers to science and history questions

Why Decreasing k in kNN Increases Complexity

· 6 min read · Science

Decreasing k in k-nearest neighbours increases model complexity because the prediction for each point is based on fewer, closer neighbours, so the decision boundary becomes more flexible and can fit local idiosyncrasies of the training data. In complexity terms, a smaller k means the model has higher variance and lower bias, making it more sensitive to noise and small fluctuations in the data.

Background: What k Controls in kNN

k-nearest neighbours (kNN) is a non-parametric method used for classification and regression. For a new query point, the algorithm finds the k training points closest to it (by a distance metric such as Euclidean distance) and predicts the majority class (classification) or the average of their target values (regression). The value of k is a hyperparameter chosen before training. It directly controls the size of the neighbourhood used for each prediction.

Model complexity in machine learning refers to the flexibility of the model's decision boundary. A complex model can represent intricate, wiggly boundaries that separate individual training points. A simple model produces smooth, rigid boundaries. In kNN, k is the primary knob for trading off between these two extremes.

How Smaller k Leads to More Complex Decision Boundaries

When k is large, each prediction averages over many neighbours, which smooths out local variations. The decision boundary tends to be simple and stable. When k is small, each prediction depends on only a few nearby points. The boundary can bend sharply to accommodate individual points, producing a highly irregular shape. For example, with k = 1, the prediction for a query point is simply the label of its single nearest training point. The decision boundary becomes the Voronoi tessellation of the training data: every training point owns a cell, and the boundary is the set of points equidistant from two training points. This boundary is maximally sensitive to the exact positions of individual points, so adding or removing one point can change predictions in a local region.

In contrast, with a very large k (approaching the number of training points), the prediction for every query becomes the global majority class or global mean, yielding a constant prediction and a trivial, low-complexity model. Thus, as k decreases from large to small, the model moves from high bias and low variance to low bias and high variance.

The Bias–Variance Trade-off in kNN

The bias–variance trade-off explains why smaller k increases complexity. Bias is error from overly simplistic assumptions; variance is error from sensitivity to training data fluctuations.

  • Large k: High bias, low variance. The model is stable but may underfit, missing local patterns.
  • Small k: Low bias, high variance. The model can capture local patterns but may overfit, treating noise as signal.

Because complexity is often defined as the ability to fit diverse patterns (low bias), decreasing k increases complexity. However, this complexity comes at the cost of stability: predictions can change drastically with small perturbations in the training set.

Concrete Example: k = 1 vs k = 15

Imagine a two-class classification problem with a noisy circular boundary. With k = 1, the decision boundary will trace the training points exactly, creating islands and peninsulas around mislabeled points. The model will have near-zero training error but poor test error. With k = 15, the boundary will be smoother, ignoring isolated points, and will generalise better if the true boundary is smooth. This illustrates how decreasing k makes the model more complex and more prone to overfitting.

In regression, a small k produces a step-like, jagged prediction function that follows local fluctuations. A large k produces a smoother, flatter function. The jaggedness is a direct visual sign of higher complexity.

Choosing k: Practical Considerations

Selecting k is a balance between complexity and generalisation. Common practices include:

  1. Use cross-validation to evaluate a range of k values (e.g., 1 to 30) and pick the one with best validation performance.
  2. For classification, odd values of k avoid ties in binary problems.
  3. Start with k ≈ √n, where n is the number of training samples, as a rough heuristic.
  4. Scale features before computing distances, because kNN is sensitive to feature scales.
  5. Consider distance weighting (e.g., weight neighbours by inverse distance) to reduce sensitivity when k is small.

Smaller k values are more appropriate when the data is dense and clean, and the decision boundary is highly non-linear. Larger k values are better when data is noisy or when a smooth boundary is expected.

Common Problems with Very Small k

Decreasing k too far introduces several issues:

  • Overfitting: The model memorises training noise, leading to poor generalisation.
  • High variance: Small changes in training data cause large changes in predictions.
  • Sensitivity to outliers: A single mislabeled point can dominate a local region.
  • Computational cost at prediction time: Although kNN is a lazy learner, smaller k does not reduce the need to compute distances to all training points; it only changes how many neighbours are used. However, the complexity of the decision boundary itself is higher.
  • Class imbalance: With small k, minority class points may be outvoted easily.

These problems are symptoms of increased model complexity.

kNN Compared to Other Models

kNN with small k is often compared to other high-complexity models. For instance, a decision tree with deep splits is complex; a shallow tree is simple. A 1-nearest-neighbour classifier is analogous to a model that can create arbitrarily fine partitions, similar to a very deep tree. Conversely, kNN with large k resembles a linear model in its simplicity, though it is not linear. Understanding this spectrum helps in model selection.

Frequently Asked Questions

Does decreasing k always increase complexity?

In the standard bias–variance sense, yes: smaller k reduces bias and increases variance, which corresponds to higher complexity. However, if the data is extremely noisy, a very small k may simply produce erratic predictions that are not useful, but the model's flexibility is still higher.

Why is k=1 the most complex kNN model?

With k=1, each prediction depends on a single training point, so the decision boundary can adapt to every individual point. This yields the highest flexibility and lowest bias among kNN models, hence the highest complexity.

Can a large k lead to overfitting?

No, a very large k typically leads to underfitting (high bias) because the model becomes too smooth and ignores local patterns. Overfitting is associated with small k.

How does the distance metric affect complexity?

The distance metric defines the neighbourhood shape. Different metrics (Euclidean, Manhattan, etc.) can change which points are considered neighbours, but the general relationship between k and complexity remains: smaller k yields more local, flexible boundaries.

Is kNN considered a high-complexity model overall?

kNN's complexity depends on k. With small k, it can be highly complex; with large k, it can be quite simple. It is not inherently high or low complexity without specifying k.

What happens if k equals the number of training points?

Then every prediction is based on all training points, resulting in the global majority class or mean. The model is extremely simple and has high bias.

In this article
  1. Background: What k Controls in kNN
  2. How Smaller k Leads to More Complex Decision Boundaries
  3. The Bias–Variance Trade-off in kNN
  4. Concrete Example: k = 1 vs k = 15
  5. Choosing k: Practical Considerations
  6. Common Problems with Very Small k
  7. kNN Compared to Other Models
  8. Frequently Asked Questions