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

Method __init__

machine_learning/k_nearest_neighbours.py:24–34  ·  view source on GitHub ↗

Create a kNN classifier using the given training data and class labels

(
        self,
        train_data: np.ndarray[float],
        train_target: np.ndarray[int],
        class_labels: list[str],
    )

Source from the content-addressed store, hash-verified

22
23class KNN:
24 def __init__(
25 self,
26 train_data: np.ndarray[float],
27 train_target: np.ndarray[int],
28 class_labels: list[str],
29 ) -> None:
30 """
31 Create a kNN classifier using the given training data and class labels
32 """
33 self.data = zip(train_data, train_target)
34 self.labels = class_labels
35
36 @staticmethod
37 def _euclidean_distance(a: np.ndarray[float], b: np.ndarray[float]) -> float:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected