Stop stretching your T-SNE, UMAP, and networks!

(source)

Did you know that T-SNE and UMAP have deep connections with visual network analysis? All those visualization techniques have something in common that is also radically different to most traditional techniques used in science, such as line charts, bar charts and scatter plots. The most trivial consequence is that stretching them damages their interpretability.

The problem is when tools do the stretching without the user noticing, or being aware of the issue. It explains the damaged visualizations we see in some papers. Exposing that issue is my motivation for writing this piece.

T-SNE and UMAP translate multivariate data as an implicit network that is then projected onto a 2D space (and sometimes 3D). The strategy used for this projection has many similarities with the force-driven placement algorithms used in network visualization: it is iterative, it tries to gather connected nodes, etc. Without going too far down the rabbit hole, let us mention one of the key properties of such approach: the produced placement is isotropic, which means that the space is the same in all directions. You must not stretch the resulting image because it breaks its isotropy. If you stretch the visualization, the image cannot be interpreted properly because it introduces a bias – in a surprisingly literal sense of the term. That was my main point. Now I will show what it looks like and explain why it matters.

The most classic charts are stretchable

“Statistical chart” in Google images

In all kinds of scientific papers we use line charts, bar charts, scatter plots… All those charts (pie charts, parametric curves excluded) share important principles:

  • Each axis represents something known, usually a quantity but sometimes an ordinal or categorical series (eg. in a bar chart)
  • Axes are independent, which allows to give each their own graphical scale

These classic charts all rely on independent axes. You can “stretch” them along each of their axes because those are independent. More exactly, there is no natural scale choice, so different arbitrary decisions naturally lead to stretched variations of the same chart. Though this kind of stretching slightly impacts the reading, the rules for interpretation remain the same.

Different scale choices for the same line chart

Graphical stretching

Basic graphical features such as image stretching are widely available in general public software such as Word / Excel / PowerPoint and even web technology. This leads to an unreasonable amount of the infamous “PowerPoint stretching”, as I am tempted to call it. Do not do it, ever.

Mona Lisa stretched: we immediately feel the awkwardness

We live in an isotropic environment, the space of our everyday life is the same in all directions. If you are 2 meters tall when you stand, then you are also 2 meters tall when you lie in bed. In simpler words, you can rotate stuff. So if you stretch an image representing the real world, it immediately feels awkward.

Graphical stretching of a classic chart

People sometimes stretch their visualizations so that they fit in a given layout. For instance in the image below on the right, the chart has been graphically reduced horizontally. Note how, contrary to the scale-stretching, this affects the visual aspect of all graphical elements such as line thickness, text etc.

Left: non stretched chart. Right: graphically stretched chart

This stretching is bad, but it is not that bad insofar as it still respects the axes. It loosely looks like a rescaled version and we can still more or less interpret it.

Graphical stretching of an isotropic visualization

Isotropic visualizations lose their interpretive properties when we stretch them, exactly like Mona Lisa. You may feel the same awkwardness as previously. I will explain precisely why we may feel it.

T-SNE visualization, original and stretched versions
Network visualization, original and stretched versions

That stretching is bad. I am sure you would not do it. Unfortunately, that is not where it ends.

Rescaling of isotropic visualizations

There is a perverse practice that I want to debunk. Some software allows the scale-stretching of isotropic visualizations. It is perverse because it is less obvious than the graphical stretching. The bias is as bad but being less visible, it has less chances to be taken in account. It is also perverse because some tools do it naturally, which for various reasons makes people incorporate the bad practice in their work.

The scale-stretching of a visualization, contrary to the graphical stretching, does not stretch the semiotic elements such as text, lines, legend… If your data points are represented as rounds, these rounds will not be stretched in ellipses, and you might be confident that the directions of space are the same. You have no strong clue that the isotropy might be broken.

Rescaling is less visible than graphical stretching

Let me show a few examples I randomly stumbled upon. I am not doing so to shame the authors, but to give an idea of what it looks like in the real world. The image below for instance is a typical case: the data points are nice rounds but the general shape, which should be round, looks like an ellipsis. I will explain later why it should be round.

Scale-stretched T-SNE visualization (source)

The next example has both T-SNE and UMAP. The scales and the background grid show evidence that isotropy is not respected: the grid should display squares, but instead it has rectangles. The figures on the scales confirm the visual analysis. Once again the T-SNE should have the general shape of a round, but instead looks like an ellipsis.

Scale-stretched T-SNE and UMAP visualizations (source)

Below I picked a less obvious case, slightly stretched out horizontally. The background grid has rectangles instead of squares, which shows the breaking of isotropy. Because it is only slightly stretched, it is easier to miss the bias.

Scale-stretched T-SNE visualization (source)

Last but not least, a screenshot of Pajek, the famous network visualization software which inspired all the others, including Gephi. It rescales the visualization to fit the proportions of active window, breaking isotropy most of the time.

A screenshot of Pajek (source)

Pajek is a marginal problem since it is not much used for visualization. The biggest problem happens inside frameworks such as R, d3.js or Matplotlib, because of a regrettable confusion with scatter plots.

The scatter plot confusion

You have a data set where data points have (x, y) spatial coordinates, how would you represent that? Scatter plot functions offer a solution to this exact problem, so I would not blame you for using such features. Unfortunately that obvious solution is also the wrong one when it comes to UMAP, T-SNE and networks. Networks tend to have their own separate pipeline, so the issue is less critical than for UMAP and T-SNE. Indeed those do not have edges and really look like any other multivariate data set. You have to be aware that the coordinates correspond to an isotropic space, unlike other similar techniques. You have to know that bags of dots come in two very different flavors, isotropic and non-isotropic.

D3.js scatter plot from tutorial (source)

The typical use of a scatter plot is to observe how two quantitative variable change together, in terms of correlation or not. Often we have no reason to presume they are linked and we just want to monitor if it is the case. For instance we want to visualize the age (in years) and the income (in dollars per year) of a set of persons. Since you have no way to convert one unit into the other, the space is not isotropic. You can scale the axes like you want.

Benzecri’s famous technique of (multiple) correspondence analysis (MCA), popularized by the French sociologist Pierre Bourdieu, has the exact same input than T-SNE or UMAP, a multivariate data set, and a seemingly similar output: it gives 2D coordinates to the data points. However in this technique the axes are central to the interpretation. In MCA you would precisely look at the distribution along axis 1 first, then along axis 2, and reflect in terms of distribution along combinations of axes. Axes are a global thing, they apply to each and every data point. This is how the internal mechanics of MCA work.

With T-SNE and UMAP, like with networks, it is absolutely wrong to reflect in terms of axes, because the algorithm’s internal mechanics only work on local features such as proximity and distance. The resulting image can be rotated because that leaves local features unchanged. Axes mean nothing, and only the comparisons between distances are meaningful, which requires an isotropic space.

The confusing resemblance of UMAP/T-SNE with MCA or other similar techniques is unfortunate, because they are almost entirely opposed on an epistemic level. What is mandatory in one case is forbidden in the other one, and vice versa. The situation is exactly the same between networks and line charts, for example. But those look very different, so it seems more natural that they require different kinds of interpretations. UMAP and MCA both look like scatter plots, but only MCA is interpreted that way.

Allowed and forbidden transformations of different charts

The problem with stretching isotropic data vis

Let us focus on networks. If you use Force Atlas 2 in Gephi, a force-driven placement algorithm, you will obtain a certain distribution of nodes in an isotropic space. It does not mean that the distribution will be homogeneous, however. The fact that a shape is oblong or very round means something. For instance, a clique (everyone is connected to everyone) makes a perfect round.

A clique in Gephi makes a perfect round

A stable, the opposite of a clique, that is a set of entirely disconnected nodes, also makes a round.

A stable in Gephi also makes a perfect round

What do a clique and a stable have in common? All nodes are equivalent. The circular shape is produced by the perfect balance of nodes in the networks.

You might wonder why the disconnected nodes of a stable do not repulse each other infinitely far. This is what would happen in a simple layout algorithm with only attractive and repulsive forces, but we generally use an additional force to keep in check the spreading of nodes. We do that because we know that we have a limited space to visualize. UMAP and T-SNE have similar strategies and you can see it very clearly in most examples.

When the shape is compact but not exactly round, it often translates the existence of multiple disparities in the structure. Take a look at the following network, which is the neural network of a small worm known as C. Elegans. It also makes a very compact shape that some would call “hairball”, but is not a round either:

C. Elegans neural network- Layout: Force Atlas 2

The areas on the borders are “poles” or connected clusters if you prefer. The fact that they do not completely separate does not help to identify these clusters visually, but there is an underlying structure that we can reveal with an algorithm like modularity clustering:


C. Elegans with nodes colored according to modularity clustering (Louvain)

There are clusters in the structural sense even if the visual clue is weak. Visual network analysis is a large topic but the important here is just that oblong shapes are a signature of poles or connected clusters. This is the problem with stretching networks. It can create oblong shapes out of nothing and add many anti-patterns to the visualization, inducing a huge bias.

This is especially important because it turns out that in many situations, local homogeneous structures make round shapes. Take a look for instance at Martin Grandjean’s visualization of air traffic network.

Air traffic network (source)

Many local clusters or sub-clusters look like round shapes, and those who do not (like Europe) probably hide poles. Stretching the image is especially bad for these kinds of networks.

T-SNE has a very similar behavior in case of well separated sub-clusters, for instance on the classical example of classifying hand written numbers:

T-SNE also tends to make round shapes for homogeneous clusters.
Source: L. van der Maaten

UMAP is the same. In the following example we even see how the oblong shapes embed poles or sub-clusters, exactly like a network does:

In UMAP too long shapes hide poles or sub-clusters.
Source: L. McInnes

So… stop stretching your T-SNE, UMAP, and networks! It will help your interpretations.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.