Graph-Based Clustering and Data Visualization in PythonThe graphclust toolbox

Chapter 10
Comparative studies and practical guidance

The previous chapters presented each method on its own. This chapter compares them under identical conditions. It first separates the three ingredients of a graph-based map—quantization, dissimilarity, and mapping—and tests their combinations on the swiss roll. It then compares the topology-based maps quantitatively, applies them and the neighbor embeddings to two real data sets, and closes with practical advice on choosing and tuning methods.

10.1 Problem and idea

A fair comparison of mapping methods requires the same data, the same budget of representatives, and a measure that does not favor one method by construction. The measures of chapter 6 are computed here against geodesic distances on the competitive Hebbian graph of each method’s own nodes whenever a manifold is to be unfolded, and against Euclidean distances when all samples are mapped. Common parameters are set identically for all methods: tmax ⁡ = 200n adaptation steps, step sizes from 0.3 to 0.05, neighborhood ranges from 0.2n to 0.01, edge lifetimes from 0.1n to 0.5n, and the same random seed.

10.2 Quantization, dissimilarity, and mapping

Table 10.1 and fig. 10.1 report the trustworthiness of eighteen combinations on the swiss roll (2000 samples, 150 representatives): k-means or neural gas codebooks; Euclidean distances, geodesic distances on a 5-NN graph of the codebook, or geodesic distances on the competitive Hebbian (TRN) graph; and metric MDS, non-metric MDS, or Sammon’s mapping. The dissimilarity is by far the most important choice. With Euclidean distances every combination folds the roll (trustworthiness 0.91–0.93). The kNN graph of the codebook improves this only partly, because a fixed number of neighbors links some nodes across neighboring windings. The TRN graph, which links only nodes whose Voronoi cells meet inside the data, gives trustworthiness of 0.998–0.999 with every quantizer and every mapping. The choice of the mapping matters little once the dissimilarities are right.

Table 10.1. Trustworthiness at k = 5 of node maps of the swiss roll for combinations of quantization, dissimilarity, and mapping (150 nodes).
Quantization Dissimilarity metric MDS non-metric MDS Sammon
k-means Euclidean 0.925 0.926 0.932
k-means geodesic, 5-NN graph 0.957 0.957 0.959
k-means geodesic, TRN graph 0.998 0.998 0.999
neural gas Euclidean 0.913 0.918 0.925
neural gas geodesic, 5-NN graph 0.921 0.922 0.935
neural gas geodesic, TRN graph 0.998 0.998 0.998

Figure 10.1

Figure 10.1. Trustworthiness of the eighteen combinations of quantization, dissimilarity, and mapping on the swiss roll. The graph used for the geodesic distances decides the quality.

Open in ColabExample plot_01_combinations.py in the gallery

codebooks = { 
    "k-means": KMeans(n, n_init=1, random_state=0).fit(X).cluster_centers_, 
    "NG": NeuralGas(n, random_state=0).fit(X).nodes_, 
} 
mappers = { 
    "metric MDS": lambda D: MetricMDS(dissimilarity="precomputed", random_state=0).fit_transform(D), 
    "non-metric MDS": lambda D: NonMetricMDS(dissimilarity="precomputed", random_state=0).fit_transform(D), 
    "Sammon": lambda D: SammonMapping(dissimilarity="precomputed").fit_transform(D), 
} 
rows = [] 
for vq, W in codebooks.items(): 
    D_eu = np.linalg.norm(W[:, None] - W[None], axis=-1) 
    D_knn = graphs.geodesic_distances(graphs.knn_graph(W, 5), points=W, connect=True) 
    D_trn = graphs.geodesic_distances(graphs.competitive_hebbian_graph(X, W), points=W, connect=True) 
    for dist, D in [("Euclidean", D_eu), ("kNN graph", D_knn), ("TRN graph", D_trn)]: 
        for mp, f in mappers.items(): 
            Y = f(D) 
            T, C = metrics.trustworthiness_continuity(D_trn, Y, 5, precomputed=True) 
            rows.append((vq, dist, mp, T, C))
   

10.3 Topology-based maps compared

Table 10.2 and fig. 10.2 compare OVI-NG, GNLP-NG, the two TRNMap variants, CDA, and Isomap applied to the TRNMap nodes, all with 150 nodes on the swiss roll. OVI-NG, the only method with Euclidean distances, keeps the roll folded: its stresses are high and its continuity is lowest. The methods with geodesic distances reach trustworthiness and continuity above 0.98. CDA preserves short distances very well but, by design, lets long ones stretch, which shows in its stress values. DP-TRNMap and NP-TRNMap have the lowest stresses and the highest trustworthiness and continuity; Isomap on the same nodes and graph comes close, as expected, since both apply MDS to the same geodesic distances. GNLP-NG, whose online map converges to a similar configuration, is only slightly behind.

Table 10.2. Quality of node maps of the swiss roll (150 nodes; reference: geodesic distances on the competitive Hebbian graph of each method’s nodes).
Method Sammon metric MDS 1 −R2 M1(5) M2(5) AUC
OVI-NG 0.362 0.420 0.978 0.911 0.946 0.515
GNLP-NG 0.009 0.005 0.017 0.984 0.996 0.842
DP-TRNMap 0.002 0.001 0.003 0.999 0.999 0.840
NP-TRNMap 0.002 0.001 0.003 0.998 0.999 0.839
CDA 0.333 0.301 0.877 0.993 0.970 0.735
Isomap (TRN nodes) 0.003 0.001 0.004 0.997 0.997 0.834

Figure 10.2

Figure 10.2. Trustworthiness and continuity of topology-based node maps of the swiss roll as functions of the neighborhood size.

Open in ColabExample plot_02_compare_maps.py in the gallery

10.4 Real data

On the standardized Wine and Wisconsin breast cancer data there is no manifold to unroll, and the question becomes which maps keep neighborhoods and the overall arrangement. With 20% of the samples as nodes (table 10.3), DP-TRNMap has the highest trustworthiness and the lowest Sammon stress among the node maps on both data sets; GNLP-NG has the highest continuity on the breast cancer data. UMAP and t-SNE, applied to all samples and evaluated with Euclidean distances at k = 10, reach similar neighborhood scores and show the classes as separated groups (fig. 10.3); the node maps show fewer points but keep the overall geometry, including the gradual transition between the benign and malignant cases.

Table 10.3. Mapping quality on real data. Node maps: trustworthiness and continuity at k = 5 and Sammon stress against geodesic distances on the nodes’ graph; UMAP and t-SNE: all samples, k = 10, Euclidean distances.
Wine
breast cancer
Method M1 M2 Sammon M1 M2 Sammon
OVI-NG 0.913 0.919 0.137 0.876 0.931 0.213
GNLP-NG 0.924 0.961 0.042 0.849 0.951 0.061
DP-TRNMap 0.966 0.960 0.033 0.927 0.959 0.029
UMAP (all samples) 0.955 0.951 – 0.930 0.946 –
t-SNE (all samples) 0.956 0.953 – 0.950 0.939 –

Figure 10.3

Figure 10.3. Maps of the Wine (top) and breast cancer (bottom) data: GNLP-NG and DP-TRNMap node maps (nodes colored by the majority class of their samples) and UMAP and t-SNE maps of all samples.

Open in ColabExample plot_03_real_data.py in the gallery

10.5 Practical guidance

The experiments of this book suggest a few rules that hold beyond the examples shown.

Look before clustering. An iVAT image of Euclidean or fuzzy neighborhood distances, or a neighbor embedding, shows within seconds whether clusters exist and roughly how many. Remember that neither can see through chains and that neighbor embeddings exaggerate cluster separation.

Choose the clustering by the kind of cluster. Compact clusters of similar size are the domain of prototype methods. Clusters of arbitrary shape that are separated by gaps call for tree methods: Zahn’s criteria when the gaps are clear, the hybrid MST–Gath–Geva algorithm when chains or bends must be cut or a Gaussian description is wanted, HDBSCAN* when densities differ and noise must be recognized. Clusters of different density without clear gaps are handled by shared-neighbor methods: the fuzzy neighborhood similarity with hierarchical clustering for small and medium data, Louvain or Leiden on a Jaccard-weighted kNN graph for large data. Spectral clustering is a strong choice when the number of clusters is moderate and can be read from the eigengap.

Choose the map by what must be preserved. If the data lie on a manifold whose geometry matters—process trajectories, gradual transitions, physical coordinates—use geodesic distances: Isomap for clean, densely sampled data, TRNMap when the data are noisy, large, or the kNN graph is hard to tune, since quantization and competitive Hebbian learning provide both robustness and a graph without a neighborhood parameter. If the goal is to show cluster structure in high-dimensional data, use UMAP or t-SNE, initialized with a spectral or PCA layout, and do not read distances between clusters. Always report trustworthiness and continuity, or the RNX curve, with a map.

Tune the neighborhood, then forget it. Every graph method has a parameter that sets the scale of the neighborhood: k, the number of nodes, the minimal cluster size. Choose it just large enough for a connected graph and check that results are stable over a range of values; the examples of chapters 2, 5 and 8 show how wide that range usually is.

10.6 Further reading

Systematic comparisons of dimensionality reduction methods with rank-based criteria are given by Lee and Verleysen [20], Venna et al. [73], and, for neighbor embeddings, Wang et al. [91]. The combinations of topology representing networks with mapping methods are analyzed in [5, 87].