def test(data, k): random.shuffle(data) pts, labels = column(data, 0), column(data, 1) trainingData = pts[:800] trainingLabels = labels[:800] testData = pts[800:] testLabels = labels[800:] f = knn.makeKNNClassifier(trainingData, trainingLabels, k, knn.euclideanDistance) correct = 0.0 total = len(testLabels) for (point, label) in zip(testData, testLabels): if f(point) == label: correct += 1 return correct/total
def test(data, k): random.shuffle(data) pts, labels = column(data, 0), column(data, 1) trainingData = pts[:800] trainingLabels = labels[:800] testData = pts[800:] testLabels = labels[800:] f = knn.makeKNNClassifier(trainingData, trainingLabels, k, knn.euclideanDistance) correct = 0.0 total = len(testLabels) for (point, label) in zip(testData, testLabels): if f(point) == label: correct += 1 return correct / total
def test(data, k): random.seed(2003892049) random.shuffle(data) pts, labels = column(data, 0), column(data, 1) trainingData = pts[:800] trainingLabels = labels[:800] testData = pts[800:] testLabels = labels[800:] f = knn.makeKNNClassifier(trainingData, trainingLabels, k, knn.mEp4) correct = 0.0 total = len(testLabels) t1 = time.time() for (point, label) in zip(testData, testLabels): if f(point) == label: correct += 1 print "Total time: {0} s\r".format(round(time.time() - t1, 2)), sys.stdout.flush() return correct/total