mirror of
https://github.com/autistic-symposium/tensorflow-for-deep-learning-py.git
synced 2025-05-13 04:02:15 -04:00
restart this repository
This commit is contained in:
parent
1d5577b7e8
commit
532fbd7342
21 changed files with 2 additions and 2 deletions
|
@ -1,23 +0,0 @@
|
|||
import numpy as np
|
||||
|
||||
class NearestNeighbor(object):
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def train(self, X, y):
|
||||
self.Xtr = X
|
||||
self.ytr = y
|
||||
|
||||
def predict(self, X):
|
||||
num_test = X.shape[0]
|
||||
Ypred = np.zeros(num_test, dtype = self.ytr.dtype)
|
||||
|
||||
# loop over all test rows
|
||||
for i in xrange(num_test):
|
||||
# find the nearest training image to the i'th test image
|
||||
# using the L1 distance (sum of absolute value differences)
|
||||
distances = np.sum(np.abs(self.Xtr - X[i,:]), axis = 1)
|
||||
min_index = np.argmin(distances) # get the index with smallest distance
|
||||
Ypred[i] = self.ytr[min_index] # predict the label of the nearest example
|
||||
|
||||
return Ypred
|
Loading…
Add table
Add a link
Reference in a new issue