MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / _euclidean_distance

Method _euclidean_distance

machine_learning/k_nearest_neighbours.py:37–45  ·  view source on GitHub ↗

Calculate the Euclidean distance between two points >>> KNN._euclidean_distance(np.array([0, 0]), np.array([3, 4])) 5.0 >>> KNN._euclidean_distance(np.array([1, 2, 3]), np.array([1, 8, 11])) 10.0

(a: np.ndarray[float], b: np.ndarray[float])

Source from the content-addressed store, hash-verified

35
36 @staticmethod
37 def _euclidean_distance(a: np.ndarray[float], b: np.ndarray[float]) -> float:
38 """
39 Calculate the Euclidean distance between two points
40 >>> KNN._euclidean_distance(np.array([0, 0]), np.array([3, 4]))
41 5.0
42 >>> KNN._euclidean_distance(np.array([1, 2, 3]), np.array([1, 8, 11]))
43 10.0
44 """
45 return float(np.linalg.norm(a - b))
46
47 def classify(self, pred_point: np.ndarray[float], k: int = 5) -> str:
48 """

Callers 1

classifyMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected