k-Nearest Neighbors (k-NN) is a simple, non-parametric algorithm used in machine learning for classification and regression. In both cases, the input consists of the k closest training examples in the feature space. The output depends on whether k-NN is used for classification (the most common class among the k nearest neighbors is output) or regression (the average of the values of the k nearest neighbors is output).