KNN
¶
-
class
numpy_ml.nonparametric.
KNN
(k=5, leaf_size=40, classifier=True, metric=None, weights='uniform')[source]¶ A k-nearest neighbors (kNN) model relying on a ball tree for efficient computation.
Parameters: - k (int) – The number of neighbors to use during prediction. Default is 5.
- leaf_size (int) – The maximum number of datapoints at each leaf in the ball tree. Default is 40.
- classifier (bool) – Whether to treat the values in Y as class labels (classifier = True) or real-valued targets (classifier = False). Default is True.
- metric (Distance metric or None) – The distance metric to use for computing nearest neighbors. If
None, use the
euclidean()
metric by default. Default is None. - weights ({'uniform', 'distance'}) – How to weight the predictions from each neighbors. ‘uniform’ assigns uniform weights to each neighbor, while ‘distance’ assigns weights proportional to the inverse of the distance from the query point. Default is ‘uniform’.