PCA vs t-SNE: Two Views of the Same Customer Segments

A hands-on comparison of how Principal Component Analysis and t-SNE visualise the same K-means customer segments from a marketing dataset, and why the two methods tell different but complementary stories.

The business problem: customer personality analysis

A marketing team wants to stop treating every customer the same way. Instead of one generic campaign, they want to identify natural groups of customers — big spenders, deal-hunters, occasional browsers — so that offers can be tailored to each group. This exercise, often called Customer Personality Analysis, works from a dataset of roughly 2,240 households recording income, recency of last purchase, spending across product categories (wine, meat, fruit, gold), how many purchases were made through the web, catalogue or in-store, and how many marketing campaigns each household accepted in the past.

Before any of that information can be fed to an algorithm, it needs cleaning: a small number of missing income values are filled with the median (chosen over the mean because income has a long right tail of high earners, and the median resists being dragged by outliers), the registration date is converted into a 'how long has this household been a customer' feature, and categorical fields like education level and marital status are encoded numerically. A handful of engineered features are added on top: total spending across all product categories, total number of purchases, total accepted campaigns and household age.

Clustering first: K-means on standardised features

With the data cleaned, the next step is to actually find the groups. Seven behavioural features are selected — income, recency, in-store purchases, deal purchases, customer tenure in days, customer age and monthly web visits — and each is standardised with StandardScaler so that a feature measured in tens of thousands of pounds (income) doesn't automatically dominate a feature measured in single digits (deal purchases). K-means with three clusters is then fit on the standardised data.

Looking at the resulting group averages tells a clear story even before any visualisation: one cluster has income around £33k, makes about 3 in-store purchases and rarely uses deals; a second has income around £72.5k, makes over 8 in-store purchases but few deal purchases; a third sits in the middle on income (£52k) but leads on deal-seeking behaviour (5 deals on average) and has the longest tenure. In plain language: a budget-conscious segment, a high-spending low-deal-seeking segment, and a loyal deal-hunter segment.

PCA: compressing seven features into three interpretable axes

Seven standardised features are hard to plot, so Principal Component Analysis (PCA) is used to compress them into three principal components while keeping as much of the original variation as possible. In this dataset, the first three components capture about 66% of the total variance — PC1 alone explains roughly 32%, PC2 about 20%, and PC3 about 14%.

What makes PCA valuable beyond just plotting is its loadings — the coefficients that show how much each original feature contributes to each component. Here, PC1 is dominated by income and in-store purchase count (positive) and monthly web visits (negative) — it essentially separates high-income, high-in-store-purchase customers from lower-income customers who browse more online. PC2 is driven mainly by deal-seeking behaviour and tenure. When income is deliberately removed from the feature set and PCA is re-run, the structure of the components changes noticeably: the loadings redistribute across the remaining features, and the total explained variance drops, confirming that income was carrying a disproportionate share of the signal — a useful sanity check on which single feature matters most to the segmentation.

Plotting the three K-means clusters in this 3D PCA space shows groups that are reasonably separated but with some overlap at the boundaries, since PCA optimises for preserving global variance rather than for pulling similar points as close together as possible.

t-SNE: prioritising local neighbourhoods over global structure

t-SNE (t-distributed Stochastic Neighbour Embedding) takes a fundamentally different approach to the same seven standardised features. Rather than finding directions of maximum variance, t-SNE tries to preserve which points are close neighbours in the original high-dimensional space, at the cost of distorting the distances between far-apart groups. Run with a perplexity of 30 on the same data, it produces a 2D map where the three K-means clusters appear as noticeably tighter, more visually separated blobs than in the PCA plot.

This is the classic PCA-versus-t-SNE trade-off. PCA's components have a fixed, computable meaning (loadings you can read off a table), and distances between PCA points reflect genuine differences in the underlying data. t-SNE has no such interpretable axes — 't-SNE dimension 1' means nothing outside the plot it was computed for — and the distance between two well-separated t-SNE clusters is not meaningfully bigger or smaller than the distance between two moderately separated ones. What t-SNE buys in exchange is a picture that is often easier to read at a glance, especially when clusters are compact but only weakly separated in the original coordinate system.

Choosing between the two in practice

The practical takeaway is that PCA and t-SNE answer different questions and are often best used together rather than as substitutes. PCA is the right tool when you need to reduce dimensionality before further modelling (feeding fewer, decorrelated features into a downstream classifier), when you need to explain which original variables drive a pattern, or when you care about preserving genuine distances. t-SNE (or its faster, more scalable cousin UMAP) is the right tool for a final, presentation-ready visual of cluster structure, especially for a non-technical audience who wants to see 'yes, these are distinct groups' at a glance.

For this marketing dataset, the workflow that makes the most business sense is: cluster on standardised features with K-means, use PCA loadings to understand and name the resulting segments in terms customers' actual behaviour ('big spenders', 'value shoppers', 'loyal deal-hunters'), and use a t-SNE plot as the headline chart when presenting the segmentation to stakeholders who just need to see that the groups are real.

Frequently Asked Questions

Why standardise the data before PCA and K-means?

Both algorithms are sensitive to the scale of input features. Without standardisation, a feature measured in tens of thousands (income) would dominate the distance calculations and the principal components purely because of its larger numeric range, not because it is more informative. StandardScaler puts every feature on a comparable footing by giving each one zero mean and unit variance.

Can I use t-SNE output as input to another model?

Generally no. t-SNE coordinates are optimised for visualisation and are not stable or meaningful as engineered features — rerunning t-SNE with a different random seed or perplexity can produce a visually different (though structurally similar) layout, and the axes carry no consistent meaning across runs. PCA components, by contrast, are deterministic and can safely be used as inputs to downstream models.

How do you choose the number of PCA components to keep?

A common rule of thumb is to look at the cumulative explained variance ratio and keep enough components to explain 70-90% of the total variance. In this example, three components explain about 66%, which is a reasonable trade-off between simplicity (a 3D plot you can actually look at) and information retention.