K Nearest Neighbors#
A distance-based algorithm that locates the k nearest neighbors (data points) from the training set and uses a weighted vote to classify unknown samples during inference. A kernelized distance function allows the user to specify different concepts of distance to the estimator.
Note: This learner is considered a lazy learner because it does the majority of its computation during inference. For a fast spatial tree-based version, see KD Neighbors.
Data Type Compatibility: Continuous
|1||k||5||int||The number of nearest neighbors to consider when making a prediction.|
|2||weighted||true||bool||Should we use the inverse distances as confidence scores when making predictions?|
|3||kernel||Euclidean||object||The distance kernel used to compute the distance between sample points.|
This estimator does not have any additional methods.
use Rubix\ML\Classifiers\KNearestNeighbors; use Rubix\ML\Kernels\Distance\Manhattan; $estimator = new KNearestNeighbors(3, true, new Manhattan());