UUtah Fall 2026 | Data Mining | L9 - k-Means and friends
Overview
The lecture formalizes assignment-based clustering through representative sites, then compares k-means, k-median, k-medoids, and k-center objectives. It explains Gonzalez’s 2-approximation for metric k-center and Lloyd’s algorithm for squared-Euclidean k-means, including its convergence to local optima and the k-means++ initialization method that improves the odds of finding a strong solution.
Key takeaways
- K-means minimizes average squared Euclidean distance, and for fixed cluster assignments the coordinate-wise mean is the site that minimizes the cluster’s sum of squared errors.
- K-median reduces the influence of distant outliers by using unsquared distances, while k-medoids additionally requires each representative to be an observed data point.
- Gonzalez’s farthest-first algorithm gives a 2-approximation for k-center in metric spaces and applies to distances such as Jaccard without requiring Euclidean coordinates.
- Lloyd’s assignment and mean-update steps each do not increase k-means cost, but stabilization only establishes a local optimum, not the globally best clustering.
- K-means++ chooses later initial centers with probability proportional to squared distance from the nearest selected center, improving coverage before Lloyd’s optimization begins.
Chapters
- Similarity homework is due at the end of the day; late submissions within one or two days can receive partial credit.
- The one-page-per-group data collection report is due in a week and asks groups to consider how they would simulate data resembling their project dataset.
- The School of Computing career fair is Thursday from 10 a.m. to 2 p.m.; the Data Science Club’s data discovery hunt is Monday from 9 a.m. to 4 p.m.
- The input is a dataset X in a space such as R^d, a distance function, and a target cluster count K.
- Instead of storing only cluster subsets, assignment-based methods represent clusters using sites s1 through sK.
- Each point is assigned to a site, which implicitly defines the corresponding cluster.
- The assignment function maps each point x to the site minimizing its distance: arg min over sites s_j of d(x, s_j).
- Nearest-site assignments partition the space into Voronoi regions; restricting those regions to X gives the data clusters.
- The site set can be a subset of the data points, but methods such as k-means can also use sites outside the observed dataset.
- The k-means objective averages each data point’s squared distance to its assigned site.
- The standard formulation uses squared Euclidean distance in R^d and optimizes the locations of K sites.
- The objective makes clustering an explicit optimization problem, unlike procedures whose output is defined only by a sequence of merges or density rules.
- K-median minimizes the sum of distances rather than squared distances, so a very distant outlier has less influence than under k-means.
- K-medoids adds the constraint that every representative site must be an observed data point, avoiding the need to construct an average object.
- Medoids are useful for non-Euclidean data such as documents compared with Jaccard distance, and their observed examples can make cluster representatives easier to interpret.
- The k-center objective minimizes the maximum distance from any data point to its assigned site.
- Because the objective is governed by the worst-served point, k-center tends to select sites that cover outliers and extreme points.
- The formulation applies in general metric spaces rather than requiring Euclidean coordinates.
- Gonzalez’s algorithm starts with an arbitrary data point and repeatedly adds the point farthest from its nearest already-selected site.
- At each iteration, the next site addresses the point currently contributing the largest k-center cost.
- The procedure selects K sites in K passes over the data and requires the distance function to satisfy the metric triangle inequality.
- Lloyd’s algorithm initializes K sites, assigns every point to its nearest site, and replaces each site with the mean of its assigned points.
- It repeats nearest-site assignment and centroid updates until the sites stop changing or a limit such as 20 iterations is reached.
- The mean update depends on Euclidean coordinates and the squared-distance k-means objective.
- An initial set of five sites can induce Voronoi regions that split natural groups across cluster boundaries.
- After assignments are computed, each site moves to the average of the points in its region, often shifting toward a more coherent group center.
- Recomputing the Voronoi diagram after centroid updates can change assignments; once assignments and sites remain stable, the iteration stops.
- For a fixed cluster X_j, its optimal Euclidean site minimizes the sum of squared distances to the points in X_j.
- That minimizer is the coordinate-wise mean, which justifies Lloyd’s centroid update.
- The mean does not generally minimize the sum of unsquared distances, so the same update is not the correct k-median optimization step.
- Nearest-site assignment cannot increase the objective because each point moves to a site no farther away.
- Replacing each site with its cluster mean cannot increase squared-error cost because the mean minimizes that cluster’s sum of squared distances.
- The objective decreases until the algorithm stabilizes, but the finite number of assignments does not rule out exponentially many iterations in the worst case.
- A poor initial placement can split two sites across one natural group while leaving another group poorly represented.
- Lloyd’s assignment and mean-update steps can then stabilize even though a different arrangement of K sites has lower cost.
- In high-dimensional data, a two-dimensional projection or cluster variance may suggest problems, but neither necessarily reveals whether the solution is globally optimal.
- Choosing K observed points uniformly at random and rerunning Lloyd’s algorithm can help; the lowest-cost run can be retained.
- Gonzalez’s farthest-first sites give a structured initialization that tends to spread centers across the dataset.
- Neither random seeding nor Gonzalez seeding guarantees a good k-means solution in every case.
- K-means++ chooses its first center from the data and selects each subsequent center randomly with probability proportional to its squared distance from the nearest selected center.
- Squaring the distance makes points far from existing centers much more likely to be selected, encouraging coverage of distinct groups.
- After initialization, Lloyd’s algorithm refines the centers; repeated runs and selection of the best-cost result can further improve reliability.
- After one center is chosen, points in its vicinity have small squared-distance weights, while distant groups receive much larger weights.
- Once a second center covers a distant group, the remaining uncovered group becomes more likely to supply the next center.
- The method combines randomized selection with distance-based coverage rather than choosing all centers uniformly.
- For nonnegative weights w_i, normalize by their sum so each item has probability w_i divided by the total weight.
- Cumulative weight intervals let a uniform random number in [0, 1] select an item in proportion to its weight; a binary tree can support selection in logarithmic time.
- The alias method can support constant-time weighted draws, and k-means++ uses this kind of sampling to initialize Lloyd’s algorithm.
Transcript excerpt
0:18 Uh great. Let's get uh let's get started. Welcome back everyone. Um so today we'll be talking about oh assignment based clustering. Um oh this will include the kind of uh um so most famous clustering um so formulation called k means uh so the algorithm usually associated with called Lloyd's algorithm which we'll talk about today but we'll also talk about kind of um other types of clustering within this family. Uh uh um so just before we get started uh we are in the clustering part of the class and the big thing to note is that
1:09 the kind of um um homework too on the similarities due today. Uh um so is everyone done with that already? Mostly done with it. Still working on it. You feel still working on Okay. Great. There's still uh so some office hours after class today. So uh um so I'll be here for a few minutes and then there's a TA office hour starting at 12:30 over in MEB. Uh um so if you have questions on that you um um so you still have time to finish it. It's due today at the end of the day. You can of course turn it in one or two days late and we'll um oh you'll be able to get partial credit. Um the first assignment was turned back uh
1:58 as we graded we finished grading the first assignment. The grades were posted that um so I think the grades went well on that. So if you have any questions um or you think something was something was misgraded the regrade requests are through grade scope. Um okay. Uh we also kind of finished getting feedback on all the proposals. Um um so I think everyone seems to be on track for that as well.
This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.
In this course
Related notes
Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, UofU Data Science.