MCPcopy
hub / github.com/ddbourgin/numpy-ml / fit

Method fit

numpy_ml/utils/data_structures.py:234–257  ·  view source on GitHub ↗

Build a ball tree recursively using the O(M log N) `k`-d construction algorithm. Notes ----- Recursively divides data into nodes defined by a centroid `C` and radius `r` such that each point below the node lies within the hyper-sphere defined

(self, X, y=None)

Source from the content-addressed store, hash-verified

232 self.metric = metric if metric is not None else euclidean
233
234 def fit(self, X, y=None):
235 """
236 Build a ball tree recursively using the O(M log N) `k`-d construction
237 algorithm.
238
239 Notes
240 -----
241 Recursively divides data into nodes defined by a centroid `C` and radius
242 `r` such that each point below the node lies within the hyper-sphere
243 defined by `C` and `r`.
244
245 Parameters
246 ----------
247 X : :py:class:`ndarray <numpy.ndarray>` of shape `(N, M)`
248 An array of `N` examples each with `M` features.
249 y : :py:class:`ndarray <numpy.ndarray>` of shape `(N, \*)` or None
250 An array of target values / labels associated with the entries in
251 `X`. Default is None.
252 """
253 centroid, left_X, left_y, right_X, right_y = self._split(X, y)
254 self.root = BallTreeNode(centroid=centroid)
255 self.root.radius = np.max([self.metric(centroid, x) for x in X])
256 self.root.left = self._build_tree(left_X, left_y)
257 self.root.right = self._build_tree(right_X, right_y)
258
259 def _build_tree(self, X, y):
260 centroid, left_X, left_y, right_X, right_y = self._split(X, y)

Callers 1

test_ball_treeFunction · 0.95

Calls 3

_splitMethod · 0.95
_build_treeMethod · 0.95
BallTreeNodeClass · 0.85

Tested by 1

test_ball_treeFunction · 0.76