7 routes42 sections324 units

Unit 4.8 · about 2 h

159 / 324

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.

  • explain

You can now

  • 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

Study, in this order

4 steps

  1. t-SNE runs and method comparison
    Hands-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

    Depth · 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 tips
    scikit-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 parameters
    UMAP - 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_

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

  4. UMAP parameters
    UMAP - basic usage and parameters

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

    Depth · Skip the n_components and metric sections.

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.

Reproduce closed-book

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.

Traps

  • 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.

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.

Self-test

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

  2. Why scale before t-SNE or UMAP?

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

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

Completion criterion

Stop when

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

Mark passed, then open 5.1 Only mark this when you can do it without notes.

Leads to

Comes after

Resources for this unit

Also in this section

  • ISLP - Unsupervised Learning
    James, Witten, Hastie, Tibshirani and Taylorrequiredtheory
    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 problems
    Deep-MLsupportpractice
    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 data
    scikit-learnreferencereference
    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 estimators
    scikit-learnreferencereference
    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 values
    scikit-learnreferencereference
    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.

Quick find

Search Michi

Type to search every route, section, unit, topic and resource.

Enter opens the first result Esc closes

Reference

Keyboard shortcuts

n
Continue to the first unit not passed
j / k
Next / previous unit
1 2 3
Toggle learned, practised, passed
/
Open search
?
Show this help
Esc
Close open panels