k.n.n

1.0.3 • Public • Published

k-Nearest Neighbors algorithm

This is an easy-to-use micro Node module that executes a kNN algorithm.

Current version: 1.0.3


Using

The module that you require in your code is the constructor of the kNN algorithm. This constructor takes one argument - the training data.

In order to launch the algorithm, use the launch function that takes 2 arguments - the k parameter and the unknown node - and returns an object with a type value and the percentage of the accuracy.

A node is a new piece of data in the (multiple-dimensional) graph, and it's defined by the "module.Node" object, who takes the attributes of the node and it's type (label) in the argument.

You can make multiple calculations by calling the "launch" function several times, with a different k or unknown-node.


Example

kNN = require("k.n.n");

var data = [ new kNN.Node({paramA: 1, paramB: 300, type: 'typeA'}), new kNN.Node({paramA: 3, paramB: 350, type: 'typeA'}), new kNN.Node({paramA: 6, paramB: 1200, type: 'typeB'}), new kNN.Node({paramA: 8, paramB: 900, type: 'typeB'}), new kNN.Node({paramA: 1, paramB: 1220, type: 'typeC'}), new kNN.Node({paramA: 2, paramB: 900, type: 'typeC'}) ];

var example = new kNN(data);

var results = example.launch(3, new kNN.Node({paramA:4, paramB:351, type:false}));

console.log(results.type + ": "+results.percentage+"%");

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i k.n.n

      Weekly Downloads

      5

      Version

      1.0.3

      License

      BSD-2-Clause

      Last publish

      Collaborators

      • pupv20