AI Dictionary › Fondamenti AI
K-means is the most widespread and widely taught clustering algorithm: it splits a set of points into a predefined number k of groups, each represented by its own center, called a centroid, trying to minimize the distance between each point and the centroid of the group it belongs to. The number k must be chosen in advance by whoever uses the algorithm, and it is often the trickiest parameter in the whole procedure.
K-means is the most widespread and widely taught clustering algorithm: it splits a set of points into a predefined number k of groups, each represented by its own center, called a centroid, trying to minimize the distance between each point and the centroid of the group it belongs to. The number k must be chosen in advance by whoever uses the algorithm, and it is often the trickiest parameter in the whole procedure.
The algorithm proceeds through iterations: k initial centroids are chosen, usually at random, then every point is assigned to the nearest centroid, the centroids are recomputed as the average of their assigned points, and the cycle repeats until the centroids stop moving meaningfully. The result depends on the initial centroids, so in practice multiple runs with different starting points are tried and the best one is kept. Choosing the most suitable number of clusters is often left to heuristics such as the elbow method, which observes how overall error decreases as k increases.
It is used to segment customers by similar behavior, compress images by reducing the number of distinct colors, identify homogeneous zones in geographic data, and as a preliminary step in more complex pipelines, for example to build a visual vocabulary in computer vision. Its speed and simplicity often make it the first choice before trying more sophisticated clustering algorithms.
The name literally describes what it does: k is the number of groups to find, means are the averages used to compute the centroids. The underlying ideas trace back to the 1950s, with independent work in statistics and signal processing; the iterative algorithm known today as k-means is generally credited to Stuart Lloyd, who described it in a 1957 Bell Labs technical report published only in 1982, and to James MacQueen, who coined the name k-means in a 1967 paper.
K-means è l'algoritmo di clustering più diffuso e insegnato: suddivide un insieme di punti in un numero prestabilito k di gruppi, ciascuno rappresentato dal proprio centro, detto centroide, cercando di minimizzare la distanza tra ogni punto e il centroide del gruppo a cui appartiene. Il numero k va scelto in anticipo da chi usa l'algoritmo, ed è spesso il parametro più delicato di tutta la procedura.
L'algoritmo procede per iterazioni: si scelgono k centroidi iniziali, di solito in modo casuale, poi ogni punto viene assegnato al centroide più vicino, i centroidi vengono ricalcolati come media dei punti assegnati, e il ciclo si ripete finché i centroidi smettono di spostarsi in modo significativo. Il risultato dipende dai centroidi iniziali, per questo in pratica si eseguono più tentativi con punti di partenza diversi e si tiene il migliore. La scelta del numero di cluster più adatto si affida spesso a euristiche come il metodo del gomito, che osserva come diminuisce l'errore complessivo all'aumentare di k.
È usato per segmentare clienti in base a comportamenti simili, comprimere immagini riducendo il numero di colori distinti, individuare zone omogenee in dati geografici, e come passo preliminare in pipeline più complesse, ad esempio per creare un vocabolario visivo in computer vision. La sua velocità e semplicità lo rendono spesso la prima scelta prima di provare algoritmi di clustering più sofisticati.
Il nome descrive letteralmente cosa fa: k è il numero di gruppi da trovare, means sono le medie usate per calcolare i centroidi. Le idee alla base risalgono agli anni '50, con lavori indipendenti in statistica e elaborazione dei segnali; la formulazione dell'algoritmo iterativo oggi noto come k-means viene generalmente attribuita a Stuart Lloyd, che la descrisse in un rapporto tecnico dei Bell Labs del 1957 pubblicato solo nel 1982, e James MacQueen, che coniò il nome k-means in un articolo del 1967.
From our network
Magellano GPS — Fleet Tracking Made Simple
Real-time GPS tracking, remote engine lock, fuel and CO₂ reporting for your fleet.
Visit magellanogps.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.