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])
| 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 | """ |