Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from scipy.spatial import distance
- def euc(a,b):
- return distance.euclidean(a, b)
- class ScrappyKNN():
- def fit(self, x_train, y_train):
- self.x_train = x_train
- self.y_train = y_train
- predictions = []
- for row in x_test:
- label = self.closest(row)
- predictions.append(label)
- return predictions
- best_dist = euc(row, self.x_train[0])
- best_index = 0
- for i in range(1, len(self.x_train)):
- dist = euc(row, self.x_train[i])
- if dist < best_dist:
- best_dist = dist
- best_index = i
- return self.y_train[best_index]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement