# nearest-neighbors

Find nearest neighbors & classify entities based on their neighbors

## NearestNeighbors

**Kind**: global class

### new NearestNeighbors()

constructor Initializes a machine for finding nearest neighbors.

`Array`

nearestNeighbors.getNearestNeighbors(node, desiredNeighbors) ⇒ Find the specified number of nearest neighbors for the provided node.

**Kind**: instance method of `NearestNeighbors`

**Returns**: `Array`

- The nearest neighbors.

Param | Type | Description |
---|---|---|

node | `Object` |
The node to find neighbors for. |

desiredNeighbors | `Number` |
The number of neighbors to find. |

`undefined`

nearestNeighbors.setDistancesFromNeighbors(node) ⇒ Assigns a distance from supplied node to each neighbor.

**Kind**: instance method of `NearestNeighbors`

Param | Type | Description |
---|---|---|

node | `Object` |
The node to find neighbors for. |

`Array`

nearestNeighbors.getDistancesFromNeighbor(node, neighbor) ⇒ Find the range adjusted distances from supplied node to a neighbor for each feature.

**Kind**: instance method of `NearestNeighbors`

**Returns**: `Array`

- The distances from this node to the neighbor in each dimension.

Param | Type | Description |
---|---|---|

node | `Object` |
The node to determine distances from. |

neighbor | `Node` |
The neighbor to determine distances from. |

`String`

nearestNeighbors.classify(node, desiredNeighbors, key) ⇒ Classify an entity based on its neighbors.

**Kind**: instance method of `NearestNeighbors`

**Returns**: `String`

- The infered classification.

Param | Type | Description |
---|---|---|

node | `Object` |
The node to find neighbors for and classify. |

desiredNeighbors | `Number` |
The number of neighbors to find. |

key | `String` |
The key to infer a value for. |

## Scripts

`test`

– run the tests

`npm run test`

`coverage`

– generate test coverage

`npm run coverage`

`view-coverage`

– view test coverage

`npm run view-coverage`

`lint`

– lint the codebase

`npm run lint`

`write-readme`

– generate the README

`npm run write-readme`

## License

MIT @ Flip