Lecture 11a
Overview
Prof. Schniter introduces classical clustering through k-means and Lloyd's algorithm, then applies document clustering to roughly 3,400 Usenet posts from four 20 Newsgroups categories. He compares sparse TF-IDF features with low-rank methods, finding that k-means and NMF recover some categories well while SVD-based latent semantic analysis performs less consistently.
Key takeaways
- K-means minimizes summed squared distance to the nearest centroid, but Lloyd's alternating assignment-and-mean updates can settle at a local minimum, making k-means++ or multiple starts useful.
- TF-IDF balances within-document term frequency against corpus-wide rarity, helping distinctive terms matter more than common words or raw counts dominated by document length.
- The 20 Newsgroups demonstration turns about 3,400 Usenet posts and a roughly 39,000-term vocabulary into a sparse matrix suitable for clustering.
- K-means recovered comp.graphics and sci.space strongly in the example, with clusters containing about 97% and 99% of those categories respectively, but produced a mixed cluster as well.
- NMF can reveal useful document groupings beyond the original labels: it separated religious and atheist posts into groups whose top terms suggested Christian versus philosophical themes.
Chapters
- Clustering is unsupervised: partition feature-only samples into k groups that are similar within each group and dissimilar across groups.
- Euclidean distance works intuitively for simple 2D clusters, but can fail when groups form connected shapes or continua.
- The curse of dimensionality makes density estimation and clustering much harder in high-dimensional data.
- K-means chooses k centroids, each with the same dimension as a data sample, to minimize the sum of squared distances to the nearest centroid.
- The nearest-centroid assignment partitions feature space into Voronoi cells, and moving centroids can change which samples belong to each cell.
- Finding the global optimum is computationally hard, so practical methods use approximate optimization rather than an exact solution.
- Lloyd's algorithm alternates between assigning samples to their nearest centroid and resetting each centroid to the mean of its assigned samples.
- The assignments and centroids stabilize after repeated updates, at which point the algorithm terminates.
- Because Lloyd's algorithm can reach a local minimum, practitioners compare multiple random starts or use k-means++ initialization.
- The document-clustering example uses Usenet posts, short forum messages with known source categories that provide reference labels for evaluating clusters.
- The 20 Newsgroups dataset has about 1,000 documents per category; the demonstration selects four categories and roughly 3,400 posts.
- The selected groups are alt.atheism, comp.graphics, sci.space, and talk.religion.misc, whose posts contain both distinctive vocabulary and category overlap.
- A bag-of-words representation builds a corpus-wide vocabulary and represents each document with a count for every term, usually excluding stop words such as “the.”
- Raw counts can favor long documents and common terms, so TF-IDF combines normalized term frequency within a document with inverse document frequency across the corpus.
- TF-IDF gives greater weight to terms that are frequent in one document but rare across other documents, such as distinctive words in a Usenet post.
- A term-document matrix supports retrieval by ranking documents with high weights for a query term, and semantic comparisons by measuring similarity between term vectors.
- The example vocabulary contains about 39,000 terms, making the document-feature matrix large but sparse because most documents contain only a small fraction of all terms.
- Sparse matrix storage records nonzero entries, while approximate low rank and nonnegative values make PCA or SVD and NMF potential analysis tools.
- Scikit-learn's TF-IDF vectorizer converts a list of document strings into numerical features while applying stop-word handling.
- Scikit-learn k-means uses k-means++ with four clusters and stops after 21 iterations when the assignments no longer change.
- Top centroid terms make two clusters interpretable: one is associated with sci.space and another with comp.graphics.
- A column-normalized confusion matrix shows about 97% comp.graphics in one cluster and 99% sci.space in another, while religious and atheist posts overlap.
- One cluster is distributed roughly evenly across all four categories, showing that TF-IDF k-means does not recover every source category.
- Truncated SVD or PCA reduces the document-term matrix to a chosen rank, with rank four used as a natural comparison for four target categories.
- NMF is suitable for the nonnegative TF-IDF matrix and yields nonnegative topic and document representations that are easier to interpret.
- Applying SVD to document features is described as latent semantic analysis; interpreting its components requires choices about how to handle the singular-value matrix.
- SVD-based latent semantic analysis performs unevenly: some components align with comp.graphics and sci.space, but others mix categories and are slightly worse than k-means.
- NMF produces about 93% comp.graphics and 85% sci.space in two clusters, while splitting the religious and atheist posts into two internally distinct groups.
- The top NMF terms suggest that this split may separate Christian vocabulary from more philosophical discussion, and Gaussian mixture models are introduced as the next probabilistic approach.
Transcript excerpt
0:02 Hope you guys had a good weekend. Sorry for the late cancellation on Friday. So um I uploaded videos for the last unit so we can move on for the previous unit. So we can move on to the last unit of the course which is basically on various approaches to clustering. And let's first talk about what is clustering. [clears throat] So in clustering, this is another one of these um [clears throat] tasks where you only have features. So it's an unsupervised task. And your objective is to partition this data set into k different groups where the samples are similar within a group and dissimilar across groups.
0:51 So this is called clustering. Um and here when we say similar there's um different ways you can define that. So um one way is similar could mean close in uklidian distance or some other metric that's um pretty common. And so just some examples um these are with two-dimensional data. So each of these X's are just a pair of numbers and um the colors [snorts] are the results of the clustering. So originally we're just given uh all these points and then the clustering algorithm decided that these would be in one cluster, these would be in another cluster, another one and so on. And you
1:40 can see um it's clustering according to uklitian distance. So points that are close to each other are within a cluster and then points that are um spread apart are you know not in the same cluster. And [snorts] uh that's a pretty easy clustering task. Here is a slightly harder one. And here you can see um that [clears throat] there's sort of this this continuum of points that are near each other. Um, even though you know like the distance
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, Prof. Schniter.