{"course":{"slug":"machine-learning-foundations","title":"Machine Learning, Foundations","url":"https://addaly.com/learn/machine-learning-foundations","level":"intermediate","track":"start"},"lesson":{"slug":"seeing-high-dimensional-data","title":"t-SNE and UMAP, and how they mislead","url":"https://addaly.com/learn/machine-learning-foundations/seeing-high-dimensional-data","position":67,"of":92,"minutes":8,"answer":"t-SNE and UMAP preserve local neighbourhoods and deliberately distort cluster sizes and between-cluster distances, so the only reliable information in the plot is which points are neighbours; and they produce convincing clusters from pure noise.","keyIdea":"t-SNE and UMAP preserve local neighbourhoods and deliberately distort cluster sizes and between-cluster distances, so the only reliable information in the plot is which points are neighbours; and they produce convincing clusters from pure noise."},"body":{"format":"markdown","text":"## A different goal from PCA\n\nPCA preserves global structure: distances and directions across the whole dataset, as well as a linear projection can. It is often disappointing for visualisation, because two dimensions of a 300-dimensional dataset usually look like a blob.\n\nt-SNE and UMAP have a different objective: preserve **local neighbourhoods**. Points that were close in the original space should be close in the plot. Points that were far can go anywhere.\n\nThat trade produces much more revealing pictures, and it is also the source of every way these plots deceive people.\n\n```python\nfrom sklearn.manifold import TSNE\nemb = TSNE(n_components=2, perplexity=30, init=\"pca\",\n           random_state=0).fit_transform(X_reduced)\n```\n\n## Four things the plot does not tell you\n\n**1. Cluster sizes are meaningless.** t-SNE expands dense regions and contracts sparse ones, deliberately, so that dense clusters do not collapse into dots. A large blob is not a large cluster.\n\n**2. Distances between clusters are meaningless.** Two clusters at opposite ends of the plot are not more different than two adjacent ones. Only the fact that points within a cluster are neighbours is reliable.\n\n**3. Apparent clusters can be artefacts.** Run t-SNE on uniform random noise with a low perplexity and it produces convincing-looking clusters. This is not a rare pathology; it happens readily. Always run the same procedure on shuffled data before believing a structure you see.\n\n**4. The result changes with the seed and the parameters.** `perplexity` roughly sets how many neighbours each point tries to stay near, and values of 5, 30 and 100 on the same data can give visibly different pictures. Run several and report what is stable across them.\n\n## UMAP\n\nUMAP does a similar job with a different mathematical construction and three practical advantages: it is much faster on large data, it preserves more global structure than t-SNE (though still not enough to trust distances), and it can `transform` new points into an existing embedding, which t-SNE cannot do at all.\n\n```python\nimport umap\nreducer = umap.UMAP(n_neighbors=15, min_dist=0.1, random_state=0)\nemb = reducer.fit_transform(X_reduced)\n```\n\n`n_neighbors` trades local against global structure: low values emphasise fine local detail, high values the broad shape. `min_dist` controls how tightly points may pack, which affects appearance more than substance.\n\nUMAP is a free package and is now the more common choice. Its global structure is better than t-SNE's and still not a metric you should quote.\n\n## Run PCA first\n\nBoth methods are slow and both suffer in very high dimensions. The standard practice is to reduce to 30 to 50 components with PCA and then run t-SNE or UMAP on that. It is faster, it removes some noise, and it usually improves the picture.\n\n## What these are legitimately for\n\n- **Looking at your data before modelling.** If the classes visibly separate, a simple model will probably work. If they are thoroughly mixed, expect a hard problem, although note the converse does not hold, since a projection that fails to separate them does not prove no model can.\n- **Finding data problems.** Duplicate rows appear as unnaturally tight points. A mislabelled group shows up as a coloured island inside another cluster. Batch effects (data collected on different days or instruments) appear as separation by batch rather than by anything you care about, and this is one of the most valuable things these plots reveal.\n- **Inspecting embeddings.** Colour points by a known attribute and see whether the representation has organised itself by it.\n\n## What they are not for\n\nThey are not a preprocessing step for a supervised model. The output coordinates have no stable meaning, t-SNE cannot transform new data at all, and UMAP's transform is not guaranteed stable enough to serve as production features. Use PCA if you need a reduction that a model will consume.\n\nAnd they are not evidence. A convincing t-SNE plot is a hypothesis. Confirm it with a number (a silhouette score, a classifier that can tell the groups apart, a stability check) before it appears in a document that someone will act on.\n\nThe cheapest confirmation is usually a classifier. If you believe the plot shows two real groups, label the points by which group they appear in and train a simple model to predict that label from the *original* features, evaluated on held-out rows. A group that a logistic regression can recover at 0.9 AUC from three interpretable columns is a real and describable structure. One that no model can recover above chance was a shape in the projection and nothing more."},"check":{"question":"A t-SNE plot shows two tight clusters far apart and a third large diffuse one between them. What can be legitimately concluded?","options":[{"text":"The diffuse cluster is noise, since real clusters appear tight under t-SNE.","correct":false,"tempting":"Diffuseness reflects local density in the original space rather than a distinction between signal and noise."},{"text":"The third cluster contains more points, since it occupies more area.","correct":false,"tempting":"Area in a t-SNE plot reflects the method's expansion of sparse regions, not the number of points in a group."},{"text":"The two tight clusters are more different from each other than either is from the diffuse one.","correct":false,"tempting":"Between-cluster distances are not preserved, so relative separation in the plot carries no information about the original space."},{"text":"Points within each visible group were neighbours in the original space; nothing about the groups' sizes or separations can be read from the plot.","correct":true}]},"prev":{"slug":"principal-components","title":"PCA: fewer columns, and what you gave up","url":"https://addaly.com/learn/machine-learning-foundations/principal-components"},"next":{"slug":"what-an-embedding-is","title":"What an embedding actually is","url":"https://addaly.com/learn/machine-learning-foundations/what-an-embedding-is"},"authorship":"Founder and series editor: Dr Mustafa Mun. Written by AI models to a written standard. Exam keys checked blind by a second model: 3,665 of 3,666 agreed. Academic review invited.","review":{"status":"Draft, open for academic review"},"cite":"Addaly (2026) 't-SNE and UMAP, and how they mislead', in Machine Learning, Foundations. Edited by M. Mun. Addaly. Available at: https://addaly.com/learn/machine-learning-foundations/seeing-high-dimensional-data (Accessed: 13 October 2026).","licence":{"name":"CC BY-NC-SA 4.0","url":"https://creativecommons.org/licenses/by-nc-sa/4.0/"},"reader":{"schema":1,"title":"t-SNE and UMAP, and how they mislead","courseTitle":"Machine Learning, Foundations","module":{"index":7,"slug":"learning-without-labels","title":"Learning without labels, and learning a representation"},"answer":null,"keyIdea":"t-SNE and UMAP preserve local neighbourhoods and deliberately distort cluster sizes and between-cluster distances, so the only reliable information in the plot is which points are neighbours; and they produce convincing clusters from pure noise.","hero":{"kind":"plate","image":null,"alt":null,"caption":null},"blocks":[{"t":"h2","id":"a-different-goal-from-pca","runs":[{"text":"A different goal from PCA"}]},{"t":"p","runs":[{"text":"PCA preserves global structure: distances and directions across the whole dataset, as well as a linear projection can. It is often disappointing for visualisation, because two dimensions of a 300-dimensional dataset usually look like a blob."}]},{"t":"p","runs":[{"text":"t-SNE and UMAP have a different objective: preserve "},{"text":"local neighbourhoods","b":true},{"text":". Points that were close in the original space should be close in the plot. Points that were far can go anywhere."}]},{"t":"p","runs":[{"text":"That trade produces much more revealing pictures, and it is also the source of every way these plots deceive people."}]},{"t":"code","lang":"python","label":"Python","text":"from sklearn.manifold import TSNE\nemb = TSNE(n_components=2, perplexity=30, init=\"pca\",\n           random_state=0).fit_transform(X_reduced)"},{"t":"h2","id":"four-things-the-plot-does-not-tell-you","runs":[{"text":"Four things the plot does not tell you"}]},{"t":"p","runs":[{"text":"1. Cluster sizes are meaningless.","b":true},{"text":" t-SNE expands dense regions and contracts sparse ones, deliberately, so that dense clusters do not collapse into dots. A large blob is not a large cluster."}]},{"t":"p","runs":[{"text":"2. Distances between clusters are meaningless.","b":true},{"text":" Two clusters at opposite ends of the plot are not more different than two adjacent ones. Only the fact that points within a cluster are neighbours is reliable."}]},{"t":"p","runs":[{"text":"3. Apparent clusters can be artefacts.","b":true},{"text":" Run t-SNE on uniform random noise with a low perplexity and it produces convincing-looking clusters. This is not a rare pathology; it happens readily. Always run the same procedure on shuffled data before believing a structure you see."}]},{"t":"p","runs":[{"text":"4. The result changes with the seed and the parameters.","b":true},{"text":" "},{"text":"perplexity","code":true},{"text":" roughly sets how many neighbours each point tries to stay near, and values of 5, 30 and 100 on the same data can give visibly different pictures. Run several and report what is stable across them."}]},{"t":"h2","id":"umap","runs":[{"text":"UMAP"}]},{"t":"p","runs":[{"text":"UMAP does a similar job with a different mathematical construction and three practical advantages: it is much faster on large data, it preserves more global structure than t-SNE (though still not enough to trust distances), and it can "},{"text":"transform","code":true},{"text":" new points into an existing embedding, which t-SNE cannot do at all."}]},{"t":"code","lang":"python","label":"Python","text":"import umap\nreducer = umap.UMAP(n_neighbors=15, min_dist=0.1, random_state=0)\nemb = reducer.fit_transform(X_reduced)"},{"t":"p","runs":[{"text":"n_neighbors","code":true},{"text":" trades local against global structure: low values emphasise fine local detail, high values the broad shape. "},{"text":"min_dist","code":true},{"text":" controls how tightly points may pack, which affects appearance more than substance."}]},{"t":"p","runs":[{"text":"UMAP is a free package and is now the more common choice. Its global structure is better than t-SNE’s and still not a metric you should quote."}]},{"t":"h2","id":"run-pca-first","runs":[{"text":"Run PCA first"}]},{"t":"p","runs":[{"text":"Both methods are slow and both suffer in very high dimensions. The standard practice is to reduce to 30 to 50 components with PCA and then run t-SNE or UMAP on that. It is faster, it removes some noise, and it usually improves the picture."}]},{"t":"h2","id":"what-these-are-legitimately-for","runs":[{"text":"What these are legitimately for"}]},{"t":"ul","items":[[{"text":"Looking at your data before modelling.","b":true},{"text":" If the classes visibly separate, a simple model will probably work. If they are thoroughly mixed, expect a hard problem, although note the converse does not hold, since a projection that fails to separate them does not prove no model can."}],[{"text":"Finding data problems.","b":true},{"text":" Duplicate rows appear as unnaturally tight points. A mislabelled group shows up as a coloured island inside another cluster. Batch effects (data collected on different days or instruments) appear as separation by batch rather than by anything you care about, and this is one of the most valuable things these plots reveal."}],[{"text":"Inspecting embeddings.","b":true},{"text":" Colour points by a known attribute and see whether the representation has organised itself by it."}]]},{"t":"h2","id":"what-they-are-not-for","runs":[{"text":"What they are not for"}]},{"t":"p","runs":[{"text":"They are not a preprocessing step for a supervised model. The output coordinates have no stable meaning, t-SNE cannot transform new data at all, and UMAP’s transform is not guaranteed stable enough to serve as production features. Use PCA if you need a reduction that a model will consume."}]},{"t":"p","runs":[{"text":"And they are not evidence. A convincing t-SNE plot is a hypothesis. Confirm it with a number (a silhouette score, a classifier that can tell the groups apart, a stability check) before it appears in a document that someone will act on."}]},{"t":"p","runs":[{"text":"The cheapest confirmation is usually a classifier. If you believe the plot shows two real groups, label the points by which group they appear in and train a simple model to predict that label from the "},{"text":"original","i":true},{"text":" features, evaluated on held-out rows. A group that a logistic regression can recover at 0.9 AUC from three interpretable columns is a real and describable structure. One that no model can recover above chance was a shape in the projection and nothing more."}]}],"check":{"question":[{"text":"A t-SNE plot shows two tight clusters far apart and a third large diffuse one between them. What can be legitimately concluded?"}],"options":[{"text":[{"text":"The diffuse cluster is noise, since real clusters appear tight under t-SNE."}],"correct":false,"tempting":[{"text":"Diffuseness reflects local density in the original space rather than a distinction between signal and noise."}]},{"text":[{"text":"The third cluster contains more points, since it occupies more area."}],"correct":false,"tempting":[{"text":"Area in a t-SNE plot reflects the method’s expansion of sparse regions, not the number of points in a group."}]},{"text":[{"text":"The two tight clusters are more different from each other than either is from the diffuse one."}],"correct":false,"tempting":[{"text":"Between-cluster distances are not preserved, so relative separation in the plot carries no information about the original space."}]},{"text":[{"text":"Points within each visible group were neighbours in the original space; nothing about the groups’ sizes or separations can be read from the plot."}],"correct":true,"tempting":null}],"order":[2,3,0,1],"why":null},"prev":{"slug":"principal-components","title":"PCA: fewer columns, and what you gave up","minutes":9},"next":{"slug":"what-an-embedding-is","title":"What an embedding actually is","minutes":10}}}