learn-unsupervised-with-phoebe / Session 6 of 10
Learn Unsupervised with Phoebe · Session 6 of 10

Compressing the customer

You have been staring at PC1/PC2 scatter plots since session 3 without ever asking what those axes ARE. Today we open the machine that made them: PCA, the honest workhorse of dimensionality reduction - what it keeps, what it throws away, and the one preprocessing mistake that hands the whole picture to the cents column. Then the two glamorous cousins, t-SNE and UMAP: beautiful, useful, and famous for making people conclude things their plots cannot support.

🟡 Building Builder track Real PCA in the lab 45 min + self-study depth
0-3 · Welcome 3-20 · Concepts 20-40 · The projection lab 40-45 · Q&A
Part 0

Why this session exists

Every clustering scatter in this course has quietly used a trick: our customers live in three dimensions (R, F, M), and your screen has two. Something has been deciding which two directions you get to see - and that something is PCA, running for real in the lab since session 3. Trusting a tool you have not inspected is exactly the habit this course exists to break. Today: the machine that made your axes, when compression helps beyond plotting, and the two prettier cousins that make bigger pictures and bigger lies.

Live - covered in session Self-study - read after ✦ Lab moment 🥭 The Mango Lane case
★ What you walk out with today PCA as "the best flat shadow" (and the variance math behind that phrase), the numbers for our own pile (PC1 50%, PC2 37%, PC3 14% - two axes carry 86% of the story), the scale-first caution that echoes session 2, and a working rule for t-SNE/UMAP that will survive contact with any conference poster.
The honesty rail (used all course) The lab's PCA is computed for real in your browser on the scaled 300-customer sample - real components, real variance percentages. The colors in the scatter are the PLANTED truth, which only exists because the data is simulated; a real project sees the same dots in one anonymous color.
Part 1 · covers PCA itself

PCA: the best flat shadow 8 min live

Hold a 3D object over a table and it casts a 2D shadow - and DIFFERENT shadows depending on how you turn it. Some shadows are informative (a mug in profile: handle visible), some are useless (the mug from directly above: a circle). PCA finds the turning that casts the most informative flat shadow - the projection that preserves the most spread (variance) in the data. Spread is where the differences between customers live; a projection that keeps spread keeps distinctions.

The pile, with two candidate axes PC1 - most spread (kept) PC2 - less spread Points barely spread along PC2 - dropping it loses little. Variance explained (our pile) PC1 · 50% PC2 · 37% 14% PC3 - dropped PC1 + PC2 = 86% of the story kept on two axes; 14% is the price of the flat picture. PCA keeps the shadow with the most spread. The discarded direction is the loss you agreed to.
🔍 Click to zoom - two candidate axes, one kept: variance decides
LiveComponents, in plain words4 min▶

PCA hands back new axes called principal components, with three properties worth saying plainly:

  • Each component is a DIRECTION through the original features - a weighted recipe: so much frequency, so much monetary, minus so much recency. Those recipe weights are the loadings, and reading them tells you what the axis means in business terms.
  • Components are orthogonal - each new axis is at right angles to all previous ones, so no component repeats information another already captured.
  • They arrive ordered by variance explained - PC1 carries the most spread, PC2 the most of what remains, and so on. Compression is just "keep the first few, drop the rest."

On our pile, read the PC1 loadings and a story appears: frequency and monetary point one way, recency points the other. PC1 is roughly an "engagement/value" direction - VIP regulars at one end, lapsed and one-time customers at the other. The axis you have been squinting at since session 3 had a meaning all along.

Real worldLoadings are where PCA earns its keep in meetings. "PC1 = 50% of variance" impresses nobody; "the single strongest pattern in our customer base is an engagement-value axis, and here is the recipe" starts a strategy conversation. Analysts who skip the loadings ship scatter plots; analysts who read them ship narratives.
LiveThe caution: PCA centers, but does NOT scale3 min▶

PCA chases variance - so whichever column has the biggest raw variance owns PC1. Sound familiar? It should: this is session 2's cents disaster wearing a different hat. scikit-learn's PCA automatically centers the data (subtracts each column's mean) but does NOT scale it. Centering is free; scaling is YOUR job, before fit.

Skip it on our pile and the monetary column - thousands of cents against tens of days and orders - dwarfs everything. PC1 becomes "basically the cents column", the variance table declares near-total victory for one component, and the beautiful 2D picture is a picture of a unit choice. Scale first (z-scores, session 2), and the three features compete fairly for the components.

Real worldThis is the most common PCA bug in the wild precisely because nothing errors: sklearn fits happily, variance percentages come back crisp, the plot renders. The tell is a suspiciously dominant PC1 whose loadings point almost entirely at your biggest-unit column. When you see a colleague's PCA where one component "explains" nearly everything, check the units before you applaud.
Self-studyWhat PCA never sees2 min▶

Worth saying once, clearly: PCA is fully unsupervised. It never sees cluster labels, planted truth, or business meaning - it sees a cloud of scaled numbers and chases spread. When our five segments come out visibly separate on PC1/PC2, that is not PCA being clever about segments; it is the segments being different ENOUGH, in the scaled features, that the directions of biggest spread happen to run between them. If segments ever looked well-mixed in a PCA view, that would not prove they are fake - it would only mean their differences live in the directions PCA threw away. One more reason the variance receipt matters: it tells you how much room "hidden in the discarded 14%" actually has.

Part 2 · covers the use cases

When to compress 6 min live

Three features barely need compressing - our case uses PCA mostly to SEE. But real customer tables have dozens or hundreds of columns, and there compression stops being a plotting convenience and becomes engineering.

LiveThe three jobs, and the price tag6 min▶

Compression earns its place three ways:

  • Before clustering: fewer, decorrelated dimensions. Distance-based algorithms like k-means behave better when redundant, correlated columns are not double-counting the same behavior - PCA hands you axes with the redundancy squeezed out.
  • Visualization: what we have been doing all course. High-dimensional pile, two-dimensional screen; PCA picks the least-lossy flat view.
  • Noise reduction: the last components often carry measurement jitter rather than structure. Dropping them can clean the signal - compression as a filter.

How many components to keep? The working rule of thumb: keep components until the cumulative variance explained is enough for your purpose. On our pile PC1+PC2 = 86% - comfortably enough to see five segments, as the lab will show.

And the price, stated honestly: we left 14% of the story on the floor - real differences between customers that the flat picture cannot show. And we traded interpretability: a principal component is a MIX of features, not a feature. "Days since last order" is a column you can point at; "a weighted blend of F and M minus some R" needs a paragraph. Compression is a purchase, and the variance table is the receipt.

Self-studyReading the receipt in the wild2 min▶

"Enough" cumulative variance is a purpose question, not a universal threshold. For a projector slide meant to show rough structure, a lower share can serve; for feeding a clustering pipeline whose output ships to marketing, you want the receipt high enough that you can defend what was discarded. Two habits transfer to any dataset: first, always look at how the percentages DECAY - a steep drop after a few components means the data is internally redundant and compresses gracefully, while a flat, even spread means every component carries real story and compression will be bloody. Second, say the discarded share out loud in reviews ("this view drops 14% of the variance") - the sentence costs nothing and inoculates the room against treating the picture as the whole truth.

Part 3 · covers t-SNE and UMAP

t-SNE and UMAP: beautiful, useful, not to be trusted literally 6 min live

PCA's shadows are honest but stiff - straight-line projections only. t-SNE and UMAP are nonlinear embeddings that bend space to keep neighbors together, producing the gorgeous cluster islands you see in every ML blog post. They exist for one purpose: visualization of high-dimensional data, period. The danger is that the pictures are so vivid that people read them as maps. They are not maps.

One embedding plot, two readings ✓ Safe to read These points sit in the same neighborhood Local neighbors are probably similar A hypothesis worth checking in the real features Use the picture to LOOK and to ask questions. ✗ Not supported by the plot "Cluster A is bigger than B" - sizes equalized "A is far from B" - distances may mean nothing "Look, clumps!" - low perplexity clumps noise Never quote embedding geometry as a fact. PCA compresses and feeds algorithms; t-SNE/UMAP make pictures to look at - not measure.
🔍 Click to zoom - the do/do-not card for reading embedding plots
LiveThe verified honesty list4 min▶

None of this is folklore - it comes from the sources closest to the tools:

  • t-SNE cluster SIZES are meaningless. The algorithm equalizes density, so a huge diffuse group and a tiny tight one can render as similar-sized islands. Distill's "How to Use t-SNE Effectively" demonstrates this interactively.
  • t-SNE inter-cluster DISTANCES may mean nothing. Two islands far apart in the plot are not necessarily far apart in reality - same Distill source, same interactive proof.
  • Low perplexity makes pure noise look clustered. Turn the perplexity knob down and random uniform points sprout convincing clumps - the algorithm's most dangerous party trick, and session 9's theme in miniature.
  • UMAP's own FAQ blesses clustering on UMAP output only "yes, with care" - and the care is specific: use a density-based method like HDBSCAN, NOT k-means, because UMAP does not preserve density. When a tool's own authors put a warning label on a use case, the warning is the documentation.

The working rule, on one line: PCA to compress and feed algorithms; t-SNE/UMAP to LOOK; never read embedding distances or sizes as facts.

ToolWhat it preservesUse it to
PCAstraight-line projection of global spread - honestly lossy, receipt attachedcompress, decorrelate, and feed algorithms
t-SNElocal neighborhoods; sizes equalized, gaps distortedlook at high-D data and form hypotheses
UMAPlocal structure; density NOT preservedlook; cluster only "with care" - HDBSCAN, not k-means
Real worldDistill's "How to Use t-SNE Effectively" became one of the most cited visualization articles in ML precisely because the failure was epidemic: papers and blog posts drawing conclusions from island sizes and gaps that were artifacts of a perplexity setting. The article's interactive figures let you watch the same data tell different stories at different knob values - ten minutes there will inoculate you for a career.
Self-studyWhy we still love them2 min▶

After all those warnings, the honest counterweight: for LOOKING at genuinely high-dimensional data - text embeddings, image features, hundreds of behavioral columns - nonlinear embeddings routinely reveal neighborhood structure that PCA's flat shadow smears together. The pros' posture is not "never use t-SNE"; it is "use it to generate hypotheses, then verify every hypothesis in the original features." The plot is the question, never the answer. StatQuest's t-SNE and UMAP videos are a gentle next step if you want the mechanics.

Everyone projects

The projection lab 🥭 ★ 18 min · meet your own axes

The lab below runs REAL PCA on the scaled 300-customer sample - the exact computation that has been drawing your axes since session 3. Today you finally read its receipt.

Look at the scatter - it IS the projection. Three scaled features (R, F, M) flattened onto two principal components. The colors are the PLANTED truth, shown so you can judge what survived the flattening. Real projects get these dots in one anonymous color.

Read the variance table. PC1 50%, PC2 37%, PC3 14% - so PC1+PC2 carry 86% of the pile's total spread. That one row is the entire justification for trusting a 2D picture of 3D customers.

Count what compression kept. Three features became two axes, and the five planted segments are still visibly separate blobs. That is compression WORKING: 86% of the variance turned out to be enough to preserve the structure we care about.

Note what died. 14% of the variance is simply gone from this picture - and so is the ability to point at an axis and say "that is frequency." Every axis is now a mix. The plot got possible; the axes got abstract. That trade is permanent.

Connect backwards. Every clustering scatter since session 3 was THIS projection - same PCA, same axes, same 86%. You have been trusting it all along without knowing why; now you have seen the receipt, you know it earned that trust.

✦ The receipt habit From today, no PCA plot without its variance table. A 2D picture carrying 86% of the variance and one carrying 41% look equally pretty - the table is the only thing telling you which one you may believe.
Before next session

Homework 📝 ◐ 20 minutes

Check yourself

Three questions before you go 🎯 ◐ 90 seconds

1 · PCA chooses its first component as the direction that...

Variance is the whole objective: spread is where distinctions between customers live, so the max-variance shadow is the least-lossy one. PCA never sees labels (it is unsupervised), and B describes what people WISH it did. C is what happens when you forget to scale - a bug, not the design.

2 · You run sklearn's PCA on the raw Mango Lane table, monetary still in cents. What happens?

Centering is automatic; scaling is on you. Nothing errors, the variance table looks crisp, and PC1 is basically the cents column - session 2's disaster reborn. Scale first, always.

3 · Which claims can a t-SNE plot NOT support?

t-SNE equalizes density (sizes meaningless) and distorts global geometry (inter-cluster distances may mean nothing) - both demonstrated interactively in Distill's "How to Use t-SNE Effectively". Neighborhoods and hypotheses: yes. Measurements: never.

Coverage, honestly

What this session covered from the official universe

✓scikit-learn user guide 2.5 - Decomposition / PCAcomponents, variance explained, and the centers-but-does-not-scale caution
✓Distill - "How to Use t-SNE Effectively"cluster sizes meaningless, distances unreliable, low perplexity clusters noise
✓UMAP documentation FAQclustering on UMAP output "yes, with care": density-based methods, not k-means
◐DataCamp "Unsupervised Learning in Python" ch2-3t-SNE and PCA concepts covered here; the hands-on sklearn code stays with DataCamp

Certificates, videos, and graded assessments stay with the official providers - this course teaches the working core with a live in-browser lab.

Session 6 cheat sheet

PCA in one lineFinds the flat projection preserving the most variance - the best flat shadow of a higher-dimensional pile.
ComponentsNew axes: orthogonal directions through the features, ordered by variance explained. Compression = keep the first few.
LoadingsEach component's recipe over the original features. Read them to name the axis - our PC1 is roughly "engagement/value".
Our receiptPC1 50%, PC2 37%, PC3 14%. Two axes carry 86% of the story; 14% and axis interpretability are the price paid.
The cautionsklearn PCA centers but does NOT scale. Skip scaling and the cents column owns PC1 - session 2's trap, PCA edition.
When to compressPre-clustering (fewer, decorrelated dims), visualization, noise reduction. Keep components until cumulative variance is enough.
t-SNE rulesCluster sizes meaningless, inter-cluster distances may mean nothing, low perplexity clusters pure noise (Distill).
The working rulePCA to compress and feed algorithms; t-SNE/UMAP to LOOK (UMAP+clustering only "with care": HDBSCAN, not k-means). Never read embedding geometry as fact.