全部版块 我的主页
论坛 数据科学与人工智能 IT基础 JAVA语言开发
972 2
2016-06-27
K-Nearest neighbor classifier

A General purpose k-nearest neighbor classifier algorithm based on the k-d tree Javascript library develop by Ubilabs:

Methodsnew NaiveBayes()

Constructor that takes no arguments.

Example

var knn = new KNN();
train(trainingSet, predictions)

Train the Naive Bayes model to the given training set, predictions, and some options.

Arguments

  • trainingSet - A matrix of the training set.
  • trainingLabels - An array of value for each case in the training set.
  • options - Object with the options for the training.

Options

  • k - number of nearest neighbor (Default, number of label + 1).
  • distance - distance function for the algorithm, the argument is a function, not an String (by default is euclidean, you can use the functions of this repository distance).

Example

var trainingSet = [[0, 0, 0], [0, 1, 1], [1, 1, 0], [2, 2, 2], [1, 2, 2], [2, 1, 2]];var predictions = [0, 0, 0, 1, 1, 1];knn.train(trainingSet, predictions);
predict(dataset)

Predict the values of the dataset.

Arguments

  • dataset - A matrix that contains the dataset.

Example

var dataset = [[0, 0, 0],               [2, 2, 2]];var ans = knn.predict(dataset);
export()

Exports the actual K-Nearest Neighbor model to an Javascript Object.

load(model)

Returns a new K-Nearest Neighbor Classifier with the given model.

Arguments

  • model - Javascript Object generated from export() function.
AuthorsLicense

MIT

本帖隐藏的内容

knn-master.zip
大小:(8.27 KB)

 马上下载




二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2016-6-27 00:09:05
复制代码
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2016-6-27 00:09:43
复制代码
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群