Graph-Based Clustering and Data Visualization in PythonThe graphclust toolbox

Appendix A
API reference

This appendix lists every public class and function of graphclust, module by module, with the first sentence of its docstring. The lists are generated from the __all__ attribute of each module by book/build_api_appendix.py, so they are complete by construction; the full signatures, parameters, and attributes are in the online documentation and in the docstrings (help(graphclust.TRNMap)). All estimators follow the scikit-learn conventions summarized in section 1.5; the notation of the docstrings is that of table 1.1.

A.1 graphclust.graphs: Graphs from data

Name

Kind

Description

competitive_hebbian_graph

function

Induced Delaunay triangulation by competitive Hebbian learning (Martinetz 1993)

connect_components

function

Join the connected components of a graph by its shortest inter-component edges

delaunay_graph

function

Delaunay triangulation as a graph (practical up to about six dimensions)

edges_of

function

Undirected edge list (edges, weights) of a symmetric sparse graph (each edge once, i < j)

epsilon_graph

function

𝜀-neighborhood graph: samples closer than eps are linked

gabriel_graph

function

Gabriel graph: xi,xj are linked when the ball with diameter xixj¯ contains no other samp

geodesic_distances

function

All-pairs shortest-path (graph, geodesic) distances with Dijkstra’s algorithm

knn_graph

function

Symmetric k-nearest-neighbor graph

knn_indices

function

Indices and distances of the k nearest neighbors of every sample (the sample itself excluded)

minimum_spanning_tree

function

Euclidean minimal spanning tree (symmetric) of the samples or of a given weighted graph

mutual_knn_graph

function

Mutual k-nearest-neighbor graph: an edge only if each sample is among the other’s neighbors

nearest_neighbor_graph

function

Nearest neighbor graph (NNG): every sample is linked to its single nearest neighbor

neighborhood_chain

function

Edge counts of NNG, MST, RNG, Gabriel graph and Delaunay triangulation, and whether each is contained in the next (for 2-D or 3-D data)

relative_neighborhood_graph

function

Relative neighborhood graph (Toussaint): xi,xj are linked when no third sample is closer to both of them than they are to each ot

shared_neighbor_counts

function

Number of shared k-nearest neighbors mij = |Ai ∩Aj| for every pair

to_networkx

function

Convert a sparse adjacency matrix to a Graph (edge attribute weight)

A.2 graphclust.vq: Vector quantization and topology learning

Name

Kind

Description

BaseTopologyLearner

class

Common interface of the vector quantizers and topology learners

DynamicTopologyRepresentingNetwork

class

Dynamic topology representing network (DTRN; Si, Lin and Vuong 2000)

GrowWhenRequired

class

Grow when required network (GWR; Marsland, Shapiro and Nehmzow 2002)

GrowingNeuralGas

class

Growing neural gas (GNG; Fritzke 1995)

LBG

class

Linde–Buzo–Gray vector quantizer: k-means with codebook splitting

NeuralGas

class

Neural gas vector quantization (Martinetz and Schulten 1991)

TopologyRepresentingNetwork

class

Topology representing network (TRN; Martinetz and Schulten 1994)

WeightedIncrementalNetwork

class

Weighted incremental neural network (WINN; Muhammed 2004)

A.3 graphclust.cluster: Graph-based clustering

Name

Kind

Description

DensityPeaks

class

Clustering by fast search and find of density peaks (Rodriguez and Laio 2014)

FuzzyNeighborhoodClustering

class

Hierarchical clustering on the fuzzy neighborhood distance dij = 1 −sij

GraphCommunityClustering

class

Community detection on a neighborhood graph (PhenoGraph-style pipeline)

HDBSCANStar

class

HDBSCAN* (Campello, Moulavi and Sander 2013; 2015): density clustering from a spanning tree

HybridMSTGG

class

Hybrid minimal spanning tree – Gath–Geva clustering (Vathy-Fogarassy, Feil and Abonyi 2005)

JarvisPatrick

class

Jarvis–Patrick shared nearest neighbor clustering (1973)

MSTClustering

class

Minimal spanning tree clustering with Zahn’s inconsistent-edge criteria

SharedNearestNeighborClustering

class

Shared nearest neighbor density clustering (SNN; Ertöz, Steinbach and Kumar 2003)

SpectralGraphClustering

class

Normalized spectral clustering (Ng, Jordan and Weiss 2002) on a neighborhood graph

fuzzy_neighborhood_similarity

function

Transitive fuzzy neighborhood similarity (Vathy-Fogarassy, Kiss and Abonyi 2007)

jaccard_knn_graph

function

kNN graph re-weighted by the Jaccard index of the neighbor sets (PhenoGraph-style, Levine et al. 2015)

A.4 graphclust.fuzzy: Gath–Geva clustering

Name

Kind

Description

GathGeva

class

Gath–Geva (fuzzy maximum likelihood estimates) clustering

fuzzy_covariances

function

Centers vi and fuzzy covariance matrices

fuzzy_hypervolume

function

Fuzzy hypervolume FHV = ∑ ⁡ idet ⁡ F i (Gath and Geva 1989); smaller is better

labels_to_membership

function

Crisp labels to a 0/1 membership matrix of shape (n_samples, n_clusters)

A.5 graphclust.validity: Cluster validity

Name

Kind

Description

clustering_rate

function

Fraction of samples in correctly matched clusters (Hungarian matching of the labels)

dbcv

function

Density-based clustering validation (DBCV; Moulavi, Jaskowiak, Campello, Zimek and Sander 2014)

dunn_mst_index

function

Dunn-like index with MST diameters: min ⁡ i≠jδ(Ci,Cj)∕max ⁡ kdiam(Ck)

eigengap

function

Number of clusters suggested by the spectrum of a graph, and the eigenvalues

fukuyama_sugeno

function

Fukuyama–Sugeno index ∑ ⁡ k ∑ iμikm(∥x k−vi∥2−∥v i−v¯∥2); smaller is better

fuzzy_hypervolume

function

Fuzzy hypervolume FHV = ∑ ⁡ idet ⁡ F i (Gath and Geva 1989); smaller is better

A.6 graphclust.vat: Visual assessment of cluster tendency

Name

Kind

Description

ivat

function

Improved VAT image: minimax (largest MST edge on the path) distances in VAT order

vat

function

Reordered dissimilarity image and the permutation

vat_order

function

VAT ordering (Prim’s order starting from an end point of the largest dissimilarity) and the MST edge weight by which every sample was attached (0 for the first)

A.7 graphclust.manifold: Mappings

Name

Kind

Description

CurvilinearComponentAnalysis

class

Curvilinear component analysis (CCA; Demartines and Hérault 1997) and curvilinear distance analysis (CDA)

DiffusionMap

class

Diffusion maps (Coifman and Lafon 2006)

GeodesicNLPNG

class

Geodesic nonlinear projection neural gas (GNLP-NG; Estévez, Chong, Held and Pérez 2006)

IncrementalGridGrowing

class

Incremental grid growing (Blackmore and Miikkulainen 1993)

Isomap

class

Isomap (Tenenbaum, de Silva and Langford 2000)

Isotop

class

Isotop (Lee and Verleysen 2002, 2004)

LaplacianEigenmap

class

Laplacian eigenmaps (Belkin and Niyogi 2003)

LocalityPreservingProjection

class

Locality preserving projections (He and Niyogi 2003): a linear map that keeps neighbors close

MetricMDS

class

Metric multidimensional scaling

NonMetricMDS

class

Non-metric (ordinal) MDS (Kruskal 1964): preserves the rank order of the dissimilarities

OnlineVisualizationNG

class

Online visualization neural gas (OVI-NG; Estévez and Figueroa 2006)

SammonMapping

class

Sammon’s nonlinear mapping (1969)

SelfOrganizingMap

class

Kohonen’s self-organizing map (batch training)

TRNMap

class

Topology representing network map (Vathy-Fogarassy, Kiss and Abonyi 2008)

UMAPEmbedding

class

Uniform manifold approximation and projection (UMAP; McInnes, Healy and Melville 2018), NumPy implementation

classical_mds

function

Classical (Torgerson) MDS of a distance matrix

tsne

function

t-distributed stochastic neighbor embedding (van der Maaten and Hinton 2008) via scikit-learn

A.8 graphclust.metrics: Quality of maps

Name

Kind

Description

auc_rnx

function

Area under the RNX(K) curve with logarithmic K axis, ∑ ⁡ KRNX(K)∕K∕∑ K1∕K

coranking_matrix

function

Co-ranking matrix Q (Lee and Verleysen 2009)

lcmc_curve

function

Local continuity meta-criterion LCMC(K) = QNX(K)−K∕(N−1) (Chen and Buja 2009)

mapping_quality

function

All distance- and neighborhood-preservation measures of a map in one dictionary

mds_stress

function

Normalized metric MDS stress ∑ ⁡ i<j(dij∗−d ij)2∕∑ i<jdij∗2

qnx_curve

function

QNX(K) = 1 KN ∑ ⁡ h,l≤KQhl, the average overlap of the K-ary neighborhoods, K = 1..N −2

residual_variance

function

Residual variance 1 −R2(D X∗,D Y ) (Tenenbaum et al. 2000)

rnx_curve

function

RNX(K) = (N−1)QNX(K)−K N−1−K : neighborhood preservation rescaled so that a random map scores 0

sammon_stress

function

Sammon stress ES = 1 ∑ ⁡ i<jdij∗∑ ⁡ i<j(dij∗−dij)2 dij∗

topographic_error

function

Share of samples whose two nearest nodes are not adjacent in the map graph (Kiviluoto 1996)

topographic_product

function

Topographic product of Bauer and Pawelzik (1992) between node vectors and their map positions

trustworthiness_continuity

function

Trustworthiness M1(k) and continuity M2(k) (Venna and Kaski 2001)

A.9 graphclust.datasets: Data sets

Name

Kind

Description

load_boxlinecircle

function

The original ’boxlinecircle’ data of Vathy-Fogarassy and Abonyi (7100 ×3; no labels)

load_breast_cancer

function

Wisconsin diagnostic breast cancer data (569 ×30, 2 classes) as shipped with scikit-learn

load_digits

function

Handwritten digits (1797 ×64, 10 classes), a stand-in for the Semeion digits of the book

load_iris

function

Iris flowers (150 ×4, 3 classes)

load_wine

function

Wine recognition data (178 ×13, 3 cultivars)

make_boxlinecircle

function

A noisy cube, a bent line and a circle in 3-D (shapes of dimension 3, 1 and 1)

make_chainlink

function

ChainLink data: 75 points in 2-D – three compact clusters, two of which are joined by a chain of points

make_curves

function

Curves data: 267 points in 2-D forming four curved clusters of different size that nearly touch

make_s_curve

function

S-curve manifold (scikit-learn generator); y is the position along the curve

make_swiss_roll

function

Swiss roll manifold (scikit-learn generator); y is the position along the roll

make_variety

function

Variety data: 100 points in 2-D, clusters of 22 (dense, round), 26 (elongated) and 51 (sparse) points and one outlier

minmax_scale

function

Scale every feature to [0, 1] (constant features become 0)

A.10 graphclust.plotting: Plotting helpers

Name

Kind

Description

PALETTE

constant

Okabe–Ito categorical palette used by all figures

plot_component_planes

function

Component planes: the map once per feature, nodes shaded by that feature of their codebook vector

plot_decision_graph

function

Density peaks decision graph (local density against distance to a denser sample)

plot_dendrogram

function

SciPy dendrogram of a linkage matrix with an optional cut line

plot_embedding

function

Scatter plot of a 2-D embedding colored by labels (or by a continuous value)

plot_graph

function

Draw a graph whose nodes have 2-D or 3-D positions; optional data cloud X in the background

plot_partition

function

Scatter plot of 2-D (or 3-D) data colored by cluster label (noise -1 in gray)

plot_quality_curves

function

Plot several quality curves (e.g. trustworthiness against k) given as {name: values}

plot_vat

function

Show a (i)VAT image: dark diagonal blocks are clusters