wAIpoint
Italiano

Nonparametric models (kernels, nearest neighbors)

Level: Intermediate

What it is

A nonparametric model does not squeeze what it learns into a fixed number of settings. It keeps the examples (or a summary of them) and lets its complexity grow with the data. The simplest case is nearest neighbours: to classify a new point, find the most similar known examples and let them vote. Kernel methods work on the same idea of similarity between examples.

What it is for

Small or medium datasets where the shape of the answer is not obvious, and cases where you want to be able to say "it decided this because it looks like these known examples". It is also a good sanity check: if nearest neighbours already does well, the problem is mostly about having good features.

How to do it

The process, step by step. Libraries and tools change; these steps stay.

  1. Turn each example into a list of numbers (features) and rescale them so that no single feature dominates the distance.
  2. Choose what "similar" means: usually a distance such as the straight-line one, or a kernel that scores similarity.
  3. Choose how many neighbours vote (k). Small k follows the data closely and is noisy; large k is smoother but can blur real differences.
  4. Pick k on a validation set, not on the test set.
  5. To predict, find the k closest stored examples to the new one and take the majority label or the average value.
  6. If it is slow on a large dataset, use an index structure for faster neighbour search, or move to a parametric model.

Timeline

  1. 1967Nearest neighbor pattern classification (Cover and Hart). source

Sources