MCPcopy Create free account
hub / github.com/rushter/MLAlgorithms / __init__

Method __init__

mla/knn.py:12–26  ·  view source on GitHub ↗

Base class for Nearest neighbors classifier and regressor. Parameters ---------- k : int, default 5 The number of neighbors to take into account. If 0, all the training examples are used. distance_func : function, default euclidean distance

(self, k=5, distance_func=euclidean)

Source from the content-addressed store, hash-verified

10
11class KNNBase(BaseEstimator):
12 def __init__(self, k=5, distance_func=euclidean):
13 """Base class for Nearest neighbors classifier and regressor.
14
15 Parameters
16 ----------
17 k : int, default 5
18 The number of neighbors to take into account. If 0, all the
19 training examples are used.
20 distance_func : function, default euclidean distance
21 A distance function taking two arguments. Any function from
22 scipy.spatial.distance will do.
23 """
24
25 self.k = None if k == 0 else k # l[:None] returns the whole list
26 self.distance_func = distance_func
27
28 def aggregate(self, neighbors_targets):
29 raise NotImplementedError()

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected