Skip to content


KNN Regressor#

K Nearest Neighbors (KNN) is a brute-force distance-based learner that locates the k nearest training samples from the training set and averages their labels to make a prediction. K Nearest Neighbors (KNN) is considered a lazy learner because it performs most of its computation at inference time.


For a faster spatial tree-accelerated version of KNN, see KD Neighbors Regressor.

Interfaces: Estimator, Learner, Online, Persistable

Data Type Compatibility: Depends on distance kernel


# Name Default Type Description
1 k 5 int The number of nearest neighbors to consider when making a prediction.
2 weighted false bool Should we consider the distances of our nearest neighbors when making predictions?
3 kernel Euclidean Distance The distance kernel used to compute the distance between sample points.


use Rubix\ML\Regressors\KNNRegressor;
use Rubix\ML\Kernels\Distance\SafeEuclidean;

$estimator = new KNNRegressor(5, false, new SafeEuclidean());

Additional Methods#

This estimator does not have any additional methods.