MCPcopy Create free account
hub / github.com/AssemblyAI-Community/Machine-Learning-From-Scratch / _predict

Method _predict

01 KNN/KNN.py:20–30  ·  view source on GitHub ↗
(self, x)

Source from the content-addressed store, hash-verified

18 return predictions
19
20 def _predict(self, x):
21 # compute the distance
22 distances = [euclidean_distance(x, x_train) for x_train in self.X_train]
23
24 # get the closest k
25 k_indices = np.argsort(distances)[:self.k]
26 k_nearest_labels = [self.y_train[i] for i in k_indices]
27
28 # majority voye
29 most_common = Counter(k_nearest_labels).most_common()
30 return most_common[0][0]

Callers 1

predictMethod · 0.95

Calls 1

euclidean_distanceFunction · 0.70

Tested by

no test coverage detected