TL;DR
GraKeL is an open-source Python library that brings graph kernels into the modern machine learning ecosystem by adhering strictly to the scikit-learn API. It implements 15 graph kernels and 2 kernel frameworks under a unified, object-oriented design, making it straightforward to build complete classification and clustering pipelines directly on graph-structured data. Despite being Python-native, it often matches or outperforms existing C++ implementations in computational efficiency.
What Problem Does This Paper Address?
Graphs are combinatorial, non-Euclidean structures that lack the clean vector-space representation required by standard machine learning algorithms. While graph kernels bridge this gap by implicitly mapping graphs into reproducing kernel Hilbert spaces (measuring structural similarity via inner products), tooling in the field has historically been fragmented.
Prior graph kernel implementations were scattered across disparate codebases in MATLAB, C++, and Python, often lacking a common structure or object-oriented design. The prevailing alternative, the graphkernels package, wrapped C++ routines but supported only variations of five kernels and one framework, while offering rigid APIs that integrated poorly with Python's scientific stack. Standard machine learning workhorses like scikit-learn also lacked native graph input support.
Methods
GraKeL provides a modular, scikit-learn-compatible architecture designed around graph-to-kernel transformations:
- Scikit-Learn Integration: Kernels inherit from a base
Kernelclass (which itself derives fromscikit-learn'sTransformerMixin). Each kernel implements four primary methods: fit: Extracts kernel-dependent features from a collection of training graphs.fit_transform: Fits and returns the $n \times n$ training kernel matrix.transform: Computes an $m \times n$ test-versus-train kernel matrix.diagonal: Returns self-kernel values used for kernel matrix normalization.- Framework and Wrapper System: Kernels are encapsulated inside a general
GraphKernelclass, enabling kernel approximation methods (such as the Nyström method) and meta-frameworks like the Weisfeiler-Lehman (WL) algorithm, which can treat any base kernel as an argument. - Flexible Data Input: Accepts native Python iterables (adjacency matrices, edge dictionaries, vertex/edge attribute dictionaries) or custom
Graphinstances, handling discrete labels as well as continuous-valued vector attributes where supported. - Underlying Stack: Built on top of NumPy and SciPy (sparse matrix routines), Cython (for performance bottlenecks), BLISS (for graph isomorphism and canonical labeling of small subgraphs), and optional CVXOPT (for semidefinite programming to compute the Lovász number $\vartheta$).
Datasets
- Dortmund Benchmark Repository: GraKeL provides a built-in
datasetssubmodule that interfaces directly with popular benchmark datasets from Kersting et al. (2016). - ENZYMES: Used for computational speed comparisons against
graphkernels. - MUTAG: Used to demonstrate an end-to-end classification workflow using a precomputed Support Vector Classifier (SVC).
Key Insights and Ideas
- Unified Object-Oriented Interface for Combinatorial Data: Treating a graph kernel as a standard
TransformerMixintransformer allows practitioners to feed raw graph datasets straight intoPipeline,GridSearchCV, and standard estimators (e.g.,SVC(kernel='precomputed')). - Python with Cython Beats Native C++ Wrappers: Although
graphkernelsruns on C++ backends, GraKeL achieves lower wall-clock runtimes across several kernels due to optimized sparse linear algebra routines (via SciPy/NumPy) and reduced data-marshaling overhead between language runtimes. - Plug-and-Play Kernel Frameworks: By decoupling kernel representations from framework schemes, meta-frameworks like Weisfeiler-Lehman can wrap arbitrary base graph kernels rather than being hardcoded to specific subtree counters.
Key Results
- Extensive Coverage: Provides implementations of 15 graph kernels and 2 kernel frameworks, compared to only variations of 5 kernels and 1 framework in
graphkernels. - Speed Benchmarks (ENZYMES dataset):
- Vertex Histogram & Edge Histogram: GraKeL is up to an order of magnitude faster than
graphkernels. - Shortest Path Kernel: GraKeL computes the kernel in under a second ($<10^0$ s), whereas
graphkernelsrequires nearly $10^3$ seconds (roughly a $1000\times$ speedup). - Geometric Random Walk: GraKeL finishes significantly faster than
graphkernels($10^2$–$10^3$ seconds vs. $>10^3$ seconds). - Weisfeiler-Lehman Subtree: Performs competitively with the dedicated C++ implementation in
graphkernels. - End-to-End Classification: A simple out-of-the-box pipeline using the Shortest Path kernel paired with an SVM classifies the MUTAG benchmark at 84.21% test accuracy in just a few lines of code.
Limitations and Future Work
- Attribute Constraints: Not all implemented kernels support continuous-valued feature vectors; several algorithms assume purely discrete node/edge labels or completely unlabeled graphs.
- Scalability to Large Graphs: While efficient relative to prior graph kernel packages, exact kernel evaluations (especially random walk variants) remain computationally demanding on very large graphs.
- Deep Graph Learning Context: The paper focuses strictly on traditional graph kernels; it does not explore integration with modern Graph Neural Network (GNN) paradigms or PyTorch/DGL pipelines.
Summary updated