# K-Nearest Neighbours

[![Twitter Handle](https://img.shields.io/badge/Twitter-@gaohongnan-blue?style=social&logo=twitter)](https://twitter.com/gaohongnan)
[![LinkedIn Profile](https://img.shields.io/badge/@gaohongnan-blue?style=social&logo=linkedin)](https://linkedin.com/in/gao-hongnan)
[![GitHub Profile](https://img.shields.io/badge/GitHub-gao--hongnan-lightgrey?style=social&logo=github)](https://github.com/gao-hongnan)
![Tag](https://img.shields.io/badge/Tag-Organized_Chaos-orange)

```{contents}
:local:
```

K-Nearest Neighbors (KNN) is a simple and widely used supervised machine
learning algorithm. It is used for classification and regression problems in
which the goal is to predict a target label or continuous value for a given
input data sample. The basic idea behind the KNN algorithm is to determine the K
number of nearest data samples in the training set for a given test sample, and
then use the majority class or the average value of these K nearest neighbors as
the prediction.

In KNN, the value of K (the number of nearest neighbors) is a hyperparameter
that needs to be specified beforehand. Larger values of K tend to result in a
smoother and more stable prediction, while smaller values of K can lead to
overfitting, especially when the training set is small or has a high degree of
noise. The choice of K can be optimized through cross-validation or other
methods.

KNN is a non-parametric and instance-based algorithm, meaning that it does not
make any assumptions about the underlying distribution of the data and does not
require any model to be explicitly fit to the data. Instead, the algorithm
relies solely on the distances between the data samples to determine the nearest
neighbors. This makes KNN a flexible and easy-to-use algorithm for a variety of
problems.

## Table of Contents

```{tableofcontents}

```
