Ahora está siguiendo esta publicación
- Verá actualizaciones en las notificaciones de contenido en seguimiento.
- Podrá recibir correos electrónicos, en función de las preferencias de comunicación que haya establecido.
Program to find the k - nearest neighbors (kNN) within a set of points.
Distance metric used: Euclidean distance
Usage:
[neighbors distances] = kNearestNeighbors(dataMatrix, queryMatrix, k);
dataMatrix (N x D) - N vectors with dimensionality D (within which we search for the nearest neighbors)
queryMatrix (M x D) - M query vectors with dimensionality D
k (1 x 1) - Number of nearest neighbors desired
Example:
a = [1 1; 2 2; 3 2; 4 4; 5 6];
b = [1 1; 2 1; 6 2];
[neighbors distances] = kNearestNeighbors(a,b,2);
Output:
neighbors =
1 2
1 2
4 3
distances =
0 1.4142
1.0000 1.0000
2.8284 3.0000
Citar como
Ani (2026). K Nearest Neighbors (https://es.mathworks.com/matlabcentral/fileexchange/15562-k-nearest-neighbors), MATLAB Central File Exchange. Recuperado .
Agradecimientos
Inspiración para: Vector Field TB, 4-Nearest Neighbor for english letter recognition using randomized partitioning., 4-Nearest Neighbor on iris recognition using randomized partitioning., K-nearest neighbor for English letter classification by doing random partition.
Categorías
Más información sobre Statistics and Machine Learning Toolbox en Help Center y MATLAB Answers.
Información general
- Versión 1.4.0.0 (640 Bytes)
-
Sin licencia
Compatibilidad con la versión de MATLAB
- Compatible con cualquier versión
Compatibilidad con las plataformas
- Windows
- macOS
- Linux
| Versión | Publicado | Notas de la versión | Action |
|---|---|---|---|
| 1.4.0.0 | Users must NOW include a separate query matrix. This allows more input flexibility. |
||
| 1.1.0.0 | Users must not include a separate query matrix. This allows more input flexibility. |
||
| 1.0.0.0 | I am not modifying the file. Just moving it to the Statistics and Probability section. |
