Unit 8 of 8 · about 2 hours · explain

t-SNE and UMAP as guarded exploratory views

Embeddings are maps for the eyes, not measurements. Unlabeled shapes become false findings unless every knob is recorded and every shape is re-tested.

You'll be able to

  • Explain what t-SNE preserves in local neighborhoods and what it distorts in global distances, densities and cluster sizes.
  • Run t-SNE and UMAP with fixed seeds, scaled input and recorded perplexity, n_neighbors and min_dist.
  • Refuse semantic claims from embedding shapes without stability and downstream checks.

Covers

t-SNE and UMAP for guarded exploratory visualization
1

Read

In this order, only the parts listed

0 of 4 done

  1. t-SNE runs and method comparisonHands-On Machine Learning with Scikit-Learn and PyTorch - dimensionality reduction and unsupervised learning

    Book Chapter 7: LLE and Other Dimensionality Reduction Techniques, which introduces t-SNE (printed pp. 239-242), and Exercise 10 (p. 243). Notebook 07 cells: LLE section with the Swiss-roll TSNE comparison using init random and learning_rate auto; Exercise 10: t-SNE on the first 5,000 MNIST digits with digit and class-image scatterplots, then the PCA, LLE and MDS comparison

    Keep the exercise small: 5,000 points as written, not the full 70,000. The notebook warns that its MDS cells take 10 to 30 minutes; skip them or run on a subsample. Skip the Kernel PCA extra material.

  2. t-SNE behavior and practical tipsscikit-learn - decomposition, clustering and outlier detection

    2.2.9 t-SNE: local-structure focus, KL non-convexity with seed dependence, global-structure warning, PCA init mitigation, Barnes-Hut limits, perplexity and learning-rate guidance; 2.2.10 practical tips: scale features first and reconstruction error for dimension choice

  3. UMAP usage and parametersUMAP - basic usage and parameters

    Penguin data: StandardScaler before fit_transform; Digits data: fit with random_state=42, then transform on the same data, which equals embedding_

    Stay in 2D exploratory views. Skip the Bokeh hover plot.

  4. UMAP parametersUMAP - basic usage and parameters

    n_neighbors: the local versus global tradeoff; min_dist: how tightly points pack

    Skip the n_components and metric sections.

2

Focus on

  • t-SNE minimizes KL between neighborhood probabilities; the objective is non-convex, so seeds differ. Record the seed and try more than one.
  • Perplexity sets the effective neighbor count; n_neighbors trades local detail for global shape; min_dist packs or spreads the plot. None of them is a cluster count.
  • sklearn TSNE has no transform for new points; UMAP has transform. Refitting t-SNE on each new batch rebuilds the map.
  • Sizes, gaps and densities on the plot are layout artifacts until stability runs and labels say otherwise.
Common mistakes · 3
  • Clustering the 2D embedding and reporting the groups as found structure. The map distorts distances; validate in the original space.
  • Reading big gaps as big separations. min_dist and perplexity set the spread; change them and gaps move.
  • Fitting t-SNE once and shipping the picture. One seed is one local minimum; rerun and keep only stable shapes.
3

Try it yourself

Closed-book, before checking anything

Closed-book, list the guarded recipe: scale, fix the seed, record perplexity or n_neighbors with min_dist, run two seeds, and state two invalid readings: cluster size as population and gap width as distance.
4

Quiz yourself

Answer first, then mark it. Missed ones go to Review.

0 got · 0 missed

  1. 1.Two t-SNE seeds show different island counts on the same data. Which map is right?Answer

    Neither yet. Rerun several seeds, keep shapes that persist, and check them with labels or clustering in the original space.

  2. 2.Why scale before t-SNE or UMAP?Answer

    Both use neighbor distances. An unscaled large-unit feature decides every neighborhood; StandardScaler puts features on shared footing.

  3. 3.UMAP transform embeds new digits but sklearn TSNE cannot. Why?Answer

    UMAP keeps the fitted model and its transform places new points into the existing embedding. scikit-learn's TSNE has fit_transform but no transform, so new points need a refit that rebuilds the whole map.

  4. 4.A UMAP plot shows one class as three islands. Claim: three subtypes. Allowed?Answer

    As a hypothesis only. Islands can come from n_neighbors, min_dist and seed choices; test with stability runs and independent evidence.

5

Practice

  • Hands-On Machine Learning Ch7 Exercise 10: t-SNE comparison

    Exercise solutions, Exercise 10: t-SNE on the first 5,000 MNIST images with digit scatterplots, then the PCA, LLE and MDS comparison

    Fix random_state, record perplexity and learning_rate, rerun with a second seed, and write which shapes persist before any interpretation. Skip the slow MDS cells or subsample first.

You're done when

Two seeded runs agree on the shapes you describe, every knob is recorded, and you can name two invalid readings of the plot.

Only when you can do this without notes.

Leads to

Notes

Resources · 3 for this unit, 5 more in the section

Also in this section

  • ISLP - Unsupervised LearningJames, Witten, Hastie, Tibshirani and Taylor · required

    Use Chapter 12 and its Python lab for the PCA derivations (12.2, including the low-rank approximation view and proportion of variance explained) and k-means (12.4.1), plus stability and interpretation limits, beside the notebook route.

  • Deep-ML - unsupervised problemsDeep-ML · support

    Use 17 K-Means Clustering, 19 PCA, 341 Gaussian Mixture Model with EM, 259 DBSCAN and 367 Isolation Forest as unit checks after the local implementation passes. Their tests were read in review; each card states what they pin, including the 367 path-length convention.

  • scikit-learn - preprocessing datascikit-learn · reference

    Read 8.3.1 standardization with the sparse with_mean=False rule, 8.3.1.3 scaling data with outliers, and 8.3.4 categorical encoding with handle_unknown, infrequent and sparse_output behavior. Apply after the HOML notebook build works.

  • scikit-learn - pipelines and composite estimatorsscikit-learn · reference

    Read 8.1.1 Pipeline chaining with the no-leakage rule and transformer caching, and 8.1.4 ColumnTransformer for heterogeneous columns with remainder and fitted-state behavior. Use it to assemble and serialize the feature-selection pipeline.

  • scikit-learn - imputation of missing valuesscikit-learn · reference

    Read 8.4.2 univariate median and most_frequent strategies, 8.4.6 Marking imputed values with MissingIndicator or add_indicator=True for missingness flags, and 8.4.7 estimators that accept NaN directly. Decide impute-only versus impute-plus-indicator per column.