Hyperparameters

ParameterDescriptionTypical Values
n_neighbors (k)Number of neighbors3-10, or √n
metricDistance metric’euclidean’, ‘manhattan’
weightsVoting weights’uniform’, ‘distance’
algorithmSearch algorithm’auto’, ‘ball_tree’, ‘kd_tree’, ‘brute’
leaf_sizeFor tree algorithms30 (default)

Search Algorithms

AlgorithmBest ForTime Complexity
Brute ForceSmall datasetsO(n) per query
KD-TreeLow dimensions (<20)O(log n) per query
Ball TreeHigh dimensionsO(log n) per query