Graph-Based Clustering and Data Visualization in PythonThe graphclust toolbox

Chapter 6
Visual assessment and the quality of maps

Before clustering it is worth asking whether the data contain clusters at all, and after mapping, how faithful the map is. This chapter presents the VAT image, which reorders a dissimilarity matrix along the minimal spanning tree so that clusters appear as dark blocks, and its improved version iVAT. It then defines the measures used in the rest of the book to judge maps: distance-based stresses and the residual variance, trustworthiness and continuity, the co-ranking matrix with the QNX, RNX, and LCMC curves, and the topographic error and product.

6.1 Problem and idea

A dissimilarity matrix shown as a gray-scale image in an arbitrary order of the samples is noise. Ordered so that similar samples are adjacent, it shows clusters as dark squares on the diagonal. Bezdek and Hathaway [66] obtained such an order from Prim’s algorithm: start at an end of the largest dissimilarity and always append the sample closest to the samples already ordered. Because Prim’s algorithm builds the minimal spanning tree, a cluster—a subtree linked to the rest by a long edge—is visited completely before the algorithm jumps to the next one.

Judging a map is a separate question with two sides (fig. 6.1). A map should not create false neighborhoods: samples that are close in the display but not in the data mislead the viewer, and the map is then not trustworthy. It also should not tear true neighborhoods apart: samples close in the data should stay close, or the map is not continuous. No two-dimensional map of genuinely higher-dimensional data can achieve both perfectly; different methods choose different compromises, and both sides have to be measured.

Figure 6.1

Figure 6.1. Two kinds of map errors. Folding a curve makes distant samples look close (false neighbors, low trustworthiness); tearing it separates true neighbors (low continuity).

6.2 Theory

6.2.1 VAT and iVAT

Given a dissimilarity matrix D, VAT [66] computes the order π of algorithm 6.1 and displays Dππ as an image. Since the order is that of Prim’s algorithm, single-linkage clusters appear as contiguous diagonal blocks. For clusters that are elongated or connected by chains, the blocks are faint: the dissimilarities within a long cluster are large at its two ends. iVAT [67] replaces every dissimilarity by the minimax path distance, the largest edge on the MST path between the two samples. Within a cluster all such paths use only short edges, between clusters they must use a long one, so the blocks become uniform and crisp. In VAT order the transformed matrix can be computed row by row in O(N2) time: the new row of the r-th sample is the elementwise maximum of its attaching edge and the row of the sample it attaches to.

Algorithm

6.2.2 Distance preservation

Let dij∗ be the dissimilarities in the input space (Euclidean or geodesic) and d^ij = ‖yi −yj ‖ the distances in the map. Three measures summarize how well distances are kept:

ES = 1 ∑ i<jdij∗∑ i<j(dij∗−d^ij)2 dij∗ , (6.1) EMDS = ∑ i<j(dij∗−d^ij)2 ∑ i<jdij∗2 , (6.2) ERV = 1 −R2(D∗,D^). (6.3)

Sammon’s stress [68] divides each error by the input dissimilarity and therefore emphasizes small distances; the normalized metric stress weighs all errors equally and is dominated by large distances; the residual variance [6] uses the linear correlation of all pairs and is invariant to a rescaling of the map. When the purpose of a map is to unfold a manifold, the input dissimilarities should be geodesic distances: Euclidean distances penalize exactly the unrolling that the map is supposed to perform.

6.2.3 Neighborhood preservation: trustworthiness and continuity

Let ρij be the rank of sample j in the ordering of all samples by their dissimilarity from i in the input space (ρii = 0, the nearest neighbor has rank 1), and rij the same rank in the map. For a neighborhood size k, let Uk(i) be the samples among the k nearest neighbors of i in the map but not in the input space, and V k(i) the samples among the k nearest in the input space but not in the map. Venna and Kaski [69] define

M1(k) = 1 − 2 Nk(2N −3k −1)∑ i=1N ∑ j∈Uk(i)(ρij −k), (6.4) M2(k) = 1 − 2 Nk(2N −3k −1)∑ i=1N ∑ j∈V k(i)(rij −k). (6.5)

Trustworthiness M1 penalizes false neighbors in the map by how far away they really are; continuity M2 penalizes missing neighbors by how far away the map puts them. Both lie in [0,1] (one is perfect, random maps score about 0.5) and are computed for a range of k: small k tests local, large k global structure.

6.2.4 The co-ranking framework

Lee and Verleysen [20] unified the rank-based measures with the co-ranking matrix Q, whose entry Qhl counts the pairs (i,j) with ρij = h and rij = l. A perfect map has a diagonal Q; entries below the diagonal are intrusions (samples ranked closer in the map than in the data), entries above are extrusions. Trustworthiness and continuity are weighted sums of the intrusions and extrusions in the upper-left k ×k block. The average agreement of the K-ary neighborhoods,

QNX(K) = 1 KN∑ h≤K ∑ l≤KQhl,
(6.6)

is the fraction of the K nearest neighbors that are preserved. Because a random map already preserves a fraction K∕(N −1), the rescaled curve

RNX(K) = (N −1)QNX(K) −K N −1 −K
(6.7)

is zero for a random map and one for a perfect one, and the local continuity meta-criterion LCMC(K) = QNX(K) −K∕(N −1) of Chen and Buja [70] subtracts the same baseline without rescaling. The area under RNX with a logarithmic K axis,

AUC = ∑ KRNX(K)∕K ∑ K1∕K ,
(6.8)

summarizes a map by one number that weighs small neighborhoods more [21]; it is the most common single criterion in recent comparisons of embeddings.

6.2.5 Map topology

For maps with a fixed or learned graph of nodes—self-organizing maps, TRNMap—two further measures check the graph itself. The topographic error [71] is the fraction of samples whose nearest and second nearest nodes are not adjacent in the map graph. The topographic product of Bauer and Pawelzik [72] compares, for every node, the order of its neighbors in the input space with their order in the map; values near zero indicate that the dimension of the map fits the data, negative values a map that is too small and folded, positive values one that is too large.

In a nutshell: Quality of a map

  • VAT and iVAT reveal cluster tendency from any dissimilarity; iVAT is clearer for chained and elongated clusters.
  • Sammon stress, metric stress, and residual variance measure distance preservation; use geodesic input distances for manifolds.
  • Trustworthiness (false neighbors) and continuity (torn neighborhoods) measure neighborhood preservation as a function of k.
  • The co-ranking matrix yields QNX, RNX, LCMC, and the AUC summary.

6.3 Using it in graphclust

graphclust.vat, graphclust.metrics

vat(D) and ivat(D) return the image and the order. sammon_stress, mds_stress, residual_variance, trustworthiness_continuity(X_high, Y, k) (k may be a list), coranking_matrix, qnx_curve, rnx_curve, lcmc_curve, auc_rnx, mapping_quality (all measures in a dictionary): the first argument is a data matrix or, with precomputed=True, a dissimilarity matrix such as geodesic distances. topographic_error(X, nodes, map_adjacency), topographic_product(nodes, positions).

The co-ranking matrix is computed once and reused for all curves:

    Q = metrics.coranking_matrix(X, Y) 
    T[name], C[name] = metrics.trustworthiness_continuity(X, Y, ks, Q=Q) 
    R[name] = metrics.rnx_curve(Q=Q) 
    print(name, {k: round(v, 3) for k, v in metrics.mapping_quality(X, Y, k=(10,)).items()}) 
    
   

6.4 Examples

6.4.1 VAT and iVAT

Figure 6.2 shows VAT and iVAT images of the ChainLink and Curves data. For the four arcs of the Curves data, the VAT image is dominated by gradients within the elongated clusters, whereas the iVAT image shows four dark blocks. ChainLink shows the limits of both images: VAT has a faint block structure, and iVAT shows only two blocks, the lower group and the chained groups together. Minimax path distances are single-linkage distances, so they cannot see through the chain either; the volume criterion of chapter 4 or a density correction is needed for that.

Figure 6.2

Figure 6.2. VAT and iVAT images of the ChainLink and Curves data. Minimax path distances turn the faint structure of the arcs into clear blocks, but, like single linkage, they keep the chained groups together.

Open in ColabExample plot_01_vat_ivat.py in the gallery

6.4.2 Measuring maps of the swiss roll

Figure 6.3 evaluates three maps of the swiss roll. The co-ranking matrix of PCA has many intrusions below the diagonal: PCA projects the roll onto a plane and puts samples of different windings on top of each other. Its trustworthiness is the lowest of the three, while its continuity is high, since a projection never tears neighborhoods. Sammon’s mapping improves trustworthiness slightly. Isomap, which uses geodesic distances, unrolls the sheet and reaches values close to one for both measures and the highest RNX curve. Its Sammon stress computed against Euclidean distances is nevertheless large (4.2 versus 0.06 for Sammon’s mapping), which illustrates why distance measures must use geodesic distances when unfolding is the goal.

Figure 6.3

Figure 6.3. Co-ranking matrix of the PCA map, and trustworthiness, continuity, and RNX(K) of PCA, Sammon’s mapping, and Isomap on the swiss roll.

Open in ColabExample plot_02_quality_measures.py in the gallery

6.5 Further reading

Bezdek and Hathaway [66] and Havens and Bezdek [67] describe VAT and iVAT. Trustworthiness and continuity are introduced by Venna and Kaski [69]; Venna et al. [73] give them an information retrieval interpretation as precision and recall of neighbors. The co-ranking framework is developed by Lee and Verleysen [20], and the AUC of RNX by Lee, Peluffo-Ordóñez, and Verleysen [21].