最近邻分类算法的python实现:KNN

jopen 9年前

 最近邻分类算法的python实现:KNN。

import knn    from knn import *  from numpy import *         dataSet, labels = createDataSet() #产生数据集       testX = array([1.2, 1.0])    k = 3    outputLabel = kNNClassify(testX, dataSet, labels, k)    print ("Your input is:", testX, "and classified to class: ", outputLabel )       testX = array([0.1, 0.3])    outputLabel = kNNClassify(testX, dataSet, labels, k)    print ("Your input is:", testX, "and classified to class: ", outputLabel)  

项目主页:http://www.open-open.com/lib/view/home/1438239968316