AI Dictionary › Fondamenti AI
K-nearest neighbors, or KNN, is one of the conceptually simplest machine learning algorithms: to classify or predict a new point, it looks at the k most similar examples it already knows and takes their most common decision, or the average of their values if the task is regression. It builds no abstract model during training: it simply stores all the data and consults it every time it has to make a prediction.
K-nearest neighbors, or KNN, is one of the conceptually simplest machine learning algorithms: to classify or predict a new point, it looks at the k most similar examples it already knows and takes their most common decision, or the average of their values if the task is regression. It builds no abstract model during training: it simply stores all the data and consults it every time it has to make a prediction.
Similarity between points is measured with a distance, often the Euclidean one, computed over the numeric features of each observation. To classify a new example, the algorithm finds the k nearest neighbors in the training dataset and assigns the most frequent class among them; k is a parameter that must be chosen carefully, too low a value makes the model sensitive to noise, too high a value flattens it and makes it lose detail. Precisely because there is no real learning phase, KNN is called a lazy algorithm: all the work happens at prediction time, not before.
It is used for recommendation systems based on similarity between users or products, pattern recognition in simple images, anomaly detection by comparing a new data point with its closest historical neighbors, and as a reference method for benchmarking more sophisticated algorithms. Its simplicity makes it an excellent teaching tool for introducing the concept of similarity in data.
The idea of classifying based on nearest neighbors was first formalized by Evelyn Fix and Joseph Hodges in a 1951 technical report prepared for the United States Air Force, within the field of nonparametric statistical analysis. The version with k neighbors, standard today, was later developed and made known by Thomas Cover and Peter Hart in a 1967 paper that formally analyzed its properties.
Il k-nearest neighbors, o KNN, è uno degli algoritmi di machine learning più semplici concettualmente: per classificare o prevedere un nuovo punto, guarda i k esempi già conosciuti più simili a lui e ne prende la decisione più comune, o la media dei loro valori se il compito è di regressione. Non costruisce alcun modello astratto durante l'addestramento: si limita a memorizzare tutti i dati e a consultarli ogni volta che deve fare una previsione.
La somiglianza tra punti si misura con una distanza, spesso quella euclidea, calcolata sulle caratteristiche numeriche di ciascuna osservazione. Per classificare un nuovo esempio, l'algoritmo trova i k vicini più prossimi nel dataset di addestramento e assegna la classe più frequente tra loro; k è un parametro che va scelto con attenzione, un valore troppo basso rende il modello sensibile al rumore, uno troppo alto lo appiattisce e gli fa perdere dettaglio. Proprio perché non c'è una fase di apprendimento vera e propria, KNN viene chiamato algoritmo pigro: tutto il lavoro avviene al momento della previsione, non prima.
È usato per sistemi di raccomandazione basati su somiglianza tra utenti o prodotti, riconoscimento di pattern in immagini semplici, individuazione di anomalie confrontando un nuovo dato con quelli storici più vicini, e come metodo di riferimento per confrontare algoritmi più sofisticati. La sua semplicità lo rende un ottimo strumento didattico per introdurre il concetto di somiglianza nei dati.
L'idea di classificare in base ai vicini più prossimi viene formalizzata per la prima volta da Evelyn Fix e Joseph Hodges in un rapporto tecnico del 1951 realizzato per l'aeronautica militare statunitense, nell'ambito di studi di analisi statistica non parametrica. La versione con k vicini, oggi standard, viene sviluppata e resa nota successivamente da Thomas Cover e Peter Hart in un articolo del 1967 che ne analizza formalmente le proprietà.
From our network
AGORÀ Intelligence — Enterprise AI Governance Platform
Govern AI at scale: policies, adoption and measurable results on your data. Built for boards and C-suite.
Visit agora-intelligence.com →From the Agora Intelligence blog
📱 Download the Android app (beta) iOS coming soon
Say what you mean. Get what you need.
Grace Certified — the AI coach that trains and certifies your prompt engineering — by Agora Intelligence.