def nearest_n(train_file, test_file): """ Performs Nearest Neighbor on data. builds kd-tree [train] nearest neighbor [test] plots error [results] """ #initialization train = Data() test = Data() kd = KDTree(1,'dc') #train train.extract(train_file) x = [10,100,500,len(train.data)] #test test.extract(test_file) y = errors(kd, x, train, test) #results graph.plot(x, y)
from data import Data from kd_tree import KDTree kd = KDTree(2) d = Data() d.extract('example.dat') print d.data kd.build_tree(d.data.keys()[:7]) print kd print kd.nearest((7,7), kd.root) #print kd