# lambda-ml.nearest-neighbors

Classification and regression using the k-nearest neighbors algorithm.

Example usage:

```
(def data [[2 3] [5 4] [9 6] [4 7] [8 1] [7 2]])
(def fit
(let [k 1]
(-> (make-nearest-neighbors-regressor k lambda-ml.distance/euclidean)
(nearest-neighbors-fit data))))
(nearest-neighbors-predict fit (map butlast data))
```

### make-nearest-neighbor-search

`(make-nearest-neighbor-search f items)`

`(make-nearest-neighbor-search f g items)`

Given a distance function f and a coll of items, each of which have an associated dimensional point, returns a function that, given k and a query item, returns a priority queue of the k nearest neighboring items. Optionally, a function g can be supplied and used to return the dimensional point for an item. Otherwise, the item itself is assumed to be the point. Assumes that all points are represented as sequences of the same dimension.

### make-nearest-neighbors-classifier

`(make-nearest-neighbors-classifier k dist)`

Returns a k-nearest neighbor classification model using the given distance function.

### make-nearest-neighbors-regressor

`(make-nearest-neighbors-regressor k dist)`

Returns a k-nearest neighbor regression model using the given distance function.

### nearest-neighbors-fit

`(nearest-neighbors-fit model data)`

`(nearest-neighbors-fit model x y)`

Fits a k-nearest neighbors model to the given training data.

### nearest-neighbors-predict

`(nearest-neighbors-predict model x)`

Predicts the values of example data using a k-nearest neighbors model.