Clustering and dimensionality reduction are the two workhorses of unsupervised learning. Clustering groups unlabeled data points by similarity…
Learn the most common clustering algorithm by walking its loop.
Clustering takes unlabeled data and groups points that are similar, revealing structure like customer segments or document topics. k-means is the go-to method: you pick k, the number of clusters, and it partitions the data into k groups, each represented by a center (centroid).
It runs a simple loop: assign each point to its nearest center, then move each center to the average of its assigned points, and repeat until the assignments stop changing.
pick k random centers repeat: assign each point to its nearest center # assignment step move each center to the mean of its points # update step until centers stop moving
Two alternating steps: assign points to the closest center, then recompute centers as the mean of their members. It converges quickly, but the result depends on the random starting centers, so it is usually run several times and the best is kept.
Add hierarchical clustering and face the 'how many clusters?' question.
Hierarchical clustering builds a tree of nested groups: start with every point as its own cluster and repeatedly merge the two closest, producing a dendrogram you can cut at any level. Unlike k-means it does not need k up front and reveals structure at multiple scales, but it is slower on large datasets.
Choosing k is the hard part of clustering, since there is no label to check against. The elbow method plots how within-cluster spread drops as k grows and looks for the bend where extra clusters stop helping. The silhouette score measures how well-separated clusters are. Both are guides, not proofs — domain knowledge decides the final call.
Also note k-means assumes roughly round, similar-sized clusters; data with odd shapes or very different densities may need methods like DBSCAN instead.
Compress many features into a few with PCA, and understand why.
High-dimensional data — hundreds or thousands of features — is hard to work with: it is slow, hard to visualize, and suffers the curse of dimensionality, where points spread out until distances lose meaning. Dimensionality reduction compresses features into a smaller set that keeps most of the useful signal.
PCA (Principal Component Analysis) is the classic linear method. It finds the directions along which the data varies most (the principal components) and projects the data onto the top few, discarding directions with little variation. Keep enough components to retain most of the variance.
Use t-SNE/UMAP to see structure, and avoid misreading the results.
When you want to eyeball structure, t-SNE and UMAP map high-dimensional data down to two dimensions for a scatter plot, preserving local neighborhoods so similar points cluster visibly. They are excellent for visualization — for example, seeing whether embeddings form meaningful groups.
t-SNE and UMAP are for visualization, not distances: cluster sizes and the gaps between clusters in the plot are not meaningful, and their layout changes with settings, so don't over-interpret. For clustering, remember to scale features first (unscaled features let one dominate distance), and don't trust a k just because the elbow looks nice — validate it against what you know about the data.
Clustering groups unlabeled data by similarity: k-means partitions into k groups via an assign-and-update loop, while hierarchical clustering builds a dendrogram without preselecting k. Dimensionality reduction compresses features: PCA projects onto the directions of greatest variance, and t-SNE/UMAP map data to 2D for visualization. Scale features first, choose k with the elbow and silhouette plus domain sense, and don't over-read t-SNE/UMAP spacing.
You have thousands of customers with 50 features each and no labels. Describe how you would reduce dimensions, cluster them into segments, choose how many segments, and check that the clusters are real rather than artifacts of unscaled features.
How does k-means clustering work?
k-means alternates assignment and update steps to partition data into k groups; results depend on the random starting centers, so it is run multiple times.
What is a key difference between hierarchical clustering and k-means?
Hierarchical clustering merges points into a dendrogram you can cut at any level, revealing multi-scale structure without preselecting the cluster count.
What does PCA do?
PCA is linear dimensionality reduction: it compresses many features into a few principal components that retain most of the variance.
What is a common mistake when reading a t-SNE or UMAP plot?
t-SNE/UMAP layouts are for seeing local structure; the spacing between clusters and their sizes shift with settings and should not be over-interpreted.