
CS-GY 6313 - Fall 2026 - Instructor: Claudio Silva
2026-11-13
Clustering as a tool for visualization
Visualization as a tool for clustering
Etienne Bernard: “… the goal of clustering is to separate a set of examples into groups called clusters”
Bernard, E. (2021). Introduction to Machine Learning, ch. Clustering. Wolfram Media.
# Code source: Gaël Varoquaux
# Modified for documentation by Jaques Grobler
# License: BSD 3 clause
#
import matplotlib.pyplot as plt
from sklearn import datasets
iris = datasets.load_iris()
_, ax = plt.subplots()
scatter = ax.scatter(iris.data[:, 2], iris.data[:, 1])
ax.set(xlabel=iris.feature_names[2], ylabel=iris.feature_names[1])
_ = ax.legend(
scatter.legend_elements()[0], iris.target_names, loc="lower right", title="Classes"
)

Objective: minimize within-cluster sum of squares \(\;\sum_{c=1}^{k} \sum_{x \in C_c} \lVert x - \mu_c \rVert^2\)
Built-in assumptions: k is known · clusters are convex and roughly spherical · similar sizes · feature scale is meaningful

Right number of clusters, wrong definition of a cluster.




The elbow says 3, the silhouette says 2, the botanist says 3.

One tree, every k: the cut height is the choice.

Same partition, different picture. Colors should not suggest an order or a meaning the clusters don’t have.

Rows are flowers, columns are measurements, the tree reorders the rows. The side bar is the species, held out.

One bar per point, grouped by cluster. Thin or negative bars are points that may be in the wrong place.
About the algorithm
About the picture
Clustering asked which points belong together.
Dimensionality reduction asks how do we draw 64 numbers per item on a 2-D screen, and it is the tool behind most cluster pictures you will meet.
Input data may have thousands or millions of dimensions!
Dimensionality Reduction represents data with fewer dimensions
Assumption: data lies on a lower dimensional space
Slides based on material from Prof. Yi Zhang
What operations did we perform? What’s the intrinsic dimensionality?
Here the underlying manifold is non-linear
Bishop, C. M. (2006). Pattern Recognition and Machine Learning, §12.1. Springer.




Illustrative kernels: Gaussian vs Student-t (1 degree of freedom), both scaled to 1 at distance 0.
https://distill.pub/2016/misread-tsne/
Wattenberg et al writes “A popular method for exploring high-dimensional data is something called t-SNE… it has an almost magical ability to create compelling two-dimensonal “maps” from data with hundreds or even thousands of dimensions. Although impressive, these images can be tempting to misread.”
Wattenberg: “The algorithm is non-linear and adapts to the underlying data, performing different transformations on different regions. Those differences can be a major source of confusion.”
Watternberg: “A second feature of t-SNE is a tuneable parameter, “perplexity,” which says (loosely) how to balance attention between local and global aspects of your data. The parameter is, in a sense, a guess about the number of close neighbors each point has. The perplexity value has a complex effect on the resulting pictures.”

“Size refers to spatial extent/area, not the number of points in the cluster.”
“The t-SNE algorithm adapts its notion of”distance” to regional density variations in the data set. As a result, it naturally expands dense clusters, and contracts sparse ones, evening out cluster sizes.”
“Distances between clusters might not mean anything”
“The next diagrams show three Gaussians of 50 points each, one pair being 5 times as far apart as another pair.”

“Random noise doesn’t always look random.”
“The next diagrams show genuinely random data, 500 points drawn from a unit Gaussian distribution in 100 dimensions. The left image is a projection onto the first two coordinates.”
“For topology, you may need more than one plot”
“The plots below show two groups of 75 points in 50 dimensional space. Both are sampled from symmetric Gaussian distributions centered at the origin, but one is 50 times more tightly dispersed than the other. The “small” distribution is in effect contained in the large one.”
https://pair-code.github.io/understanding-umap/
n_neighbors - the number of approximate nearest neighbors used to construct the initial high-dimensional graph.
min_dist - the minimum distance between points in low-dimensional space.
n_neighbors - the number of approximate nearest neighbors used to construct the initial high-dimensional graph.
min_dist - the minimum distance between points in low-dimensional space.
n_neighbors - the number of approximate nearest neighbors used to construct the initial high-dimensional graph.
min_dist - the minimum distance between points in low-dimensional space.

“However, it’s important to note that, because UMAP and t-SNE both necessarily warp the high-dimensional shape of the data when projecting to lower dimensions, any given axis or distance in lower dimensions still isn’t directly interpretable in the way of techniques such as PCA.”
Suggested reading: https://pair-code.github.io/understanding-umap/supplement.html
| PCA | t-SNE | UMAP | |
|---|---|---|---|
| Kind | linear | non-linear, neighbor graph + KL divergence | non-linear, fuzzy neighbor graph |
| Keeps | global variance | local neighborhoods | local neighborhoods, some coarse layout |
| Axes and distances mean something? | yes: axes are directions in the data | no: sizes and gaps are artifacts | no: gaps are not reliable |
| Knobs | number of components | perplexity, steps, learning rate | n_neighbors, min_dist |
| Repeatable? | yes | depends on initialization and seed | depends on seed |
| New points | transform |
refit | transform |
| Reach for it to | get a first look, denoise, preprocess | see local cluster structure on small and medium data | see structure on larger data, reuse the mapping |
trustworthiness(X, X_map, n_neighbors=k); continuity is the same function with the two spaces swappedT(k) = 1 − 2 / (N·k·(2N − 3k − 1)) · Σi Σj ∈ Ui (r(i,j) − k)
Ui = false neighbors of i (in its map neighborhood, not in its data neighborhood); r(i,j) = rank of j among i’s neighbors in the original space


Clustering: Bernard, Introduction to Machine Learning — Clustering (Wolfram), and the scikit-learn page Comparing different clustering algorithms on toy datasets
Projections, required: Wattenberg, Viégas & Johnson, How to Use t-SNE Effectively (Distill, 2016)
Coenen & Pearce, Understanding UMAP