Graph classification is the supervised task of predicting a single label for an entire graph, rather than for its individual nodes or edges. In graph learning it covers problems where each data point is a separate graph, such as a molecule judged toxic or safe, a protein structure assigned to an enzyme class, or a social network labeled by community type.
A graph classifier must turn a structure of variable size and arbitrary node ordering into a fixed-length representation and then into a class prediction. The answer must stay the same however the nodes are numbered, so every method relies on permutation-invariant operations, from classic graph kernels to modern graph neural networks.
How a graph classification pipeline works
Most current systems follow a three-stage pipeline: node-level encoding, graph-level aggregation and a final classifier. The first stage uses message passing layers, in which every node repeatedly gathers information from its neighbors, so after k layers a node embedding summarizes its k-hop neighborhood.
The second stage applies a readout function that combines all node embeddings into one graph vector. Because the order of nodes carries no meaning, the readout must be a symmetric operation such as a sum, mean or maximum. The third stage is usually a small multilayer perceptron that maps the graph vector to class probabilities trained with cross-entropy loss.
| Stage | Typical components | Output |
|---|---|---|
| Node encoding | GCN, GIN, GAT or GraphSAGE layers | One embedding per node |
| Pooling and readout | Sum, mean, attention, hierarchical pooling | One fixed-length graph vector |
| Classification head | MLP with softmax or sigmoid | Class probabilities per graph |
Readout and pooling choices
The readout decides which structural information survives into the graph representation. Sum aggregation preserves the count of patterns and is the most expressive simple choice, while mean and max discard size information that may matter, for example the number of rings in a molecule.
Hierarchical pooling coarsens the graph in several steps instead of collapsing it at once. Methods such as DiffPool learn soft cluster assignments, whereas top-k pooling and SAGPool keep only the highest-scoring nodes. The table compares common options.
| Method | Mechanism | Strength | Weakness |
|---|---|---|---|
| Sum readout | Adds all node embeddings | Keeps multiset information | Scale grows with graph size |
| Mean readout | Averages node embeddings | Stable across sizes | Loses node count |
| Attention readout | Learned weights per node | Focuses on key substructures | Extra parameters, overfitting risk |
| DiffPool | Learned soft clustering | Captures hierarchy | Quadratic memory cost |
| Top-k pooling | Keeps highest-scoring nodes | Sparse and fast | May drop useful context |
| Virtual node | Extra node linked to all others | Global information flow | Can dominate message passing |
Empirical studies often find that simple sum or mean readouts perform about as well as complex pooling once training is carefully tuned, so hierarchical pooling should be justified by validation results, not assumed.
Expressive power and the Weisfeiler-Lehman limit
Standard message passing networks can distinguish two graphs no better than the 1-dimensional Weisfeiler-Lehman test. This color refinement procedure fails on certain non-isomorphic graphs, for example two triangles versus one hexagon, which look locally identical. A graph classifier built on such layers will therefore assign them the same embedding and the same label.
The graph isomorphism network (GIN) reaches this upper bound by combining sum aggregation with an injective MLP update. Going beyond it requires higher-order networks, subgraph-based methods, positional or structural encodings such as Laplacian eigenvectors, or graph transformers that attend across all node pairs.
In practice, the WL limit matters most when labels depend on global properties such as cycles, connectivity or symmetry. Molecular tasks are a good illustration: ring membership and ring size strongly affect chemical behavior, yet plain message passing struggles to count rings. Adding cycle counts or random-walk encodings as node features is a cheap and often effective remedy.
| Approach | Idea | Cost |
|---|---|---|
| Structural encodings | Add cycle counts or random-walk features | Low, computed once per graph |
| Laplacian positional encodings | Attach eigenvector coordinates to nodes | Moderate, sign ambiguity to handle |
| Subgraph GNNs | Encode many node-marked subgraphs | High, multiplies graph size |
| Higher-order GNNs | Pass messages between node tuples | Very high, rarely scalable |
Graph kernels versus graph neural networks
Before neural methods, graph classification relied on graph kernels combined with support vector machines. A kernel counts shared substructures, such as walks, shortest paths or Weisfeiler-Lehman subtree patterns, and uses the counts as a similarity measure. Kernels remain strong baselines on small datasets.
| Aspect | Graph kernels | Graph neural networks |
|---|---|---|
| Features | Hand-designed substructure counts | Learned end to end |
| Continuous attributes | Limited support | Handled natively |
| Scalability | Kernel matrix grows quadratically | Mini-batch training on GPUs |
| Small datasets | Often competitive or better | Prone to overfitting |
| Transfer and pretraining | Not applicable | Possible with self-supervision |
Benchmarks and evaluation pitfalls
Graph classification is evaluated on collections such as the TUDataset benchmarks and the Open Graph Benchmark. Many classic datasets are very small, so a few misclassified graphs change accuracy by several points.
| Dataset | Domain | Number of graphs | Metric |
|---|---|---|---|
| MUTAG | Mutagenic compounds | 188 | Accuracy |
| PROTEINS | Protein structures | 1,113 | Accuracy |
| NCI1 | Anticancer screening | 4,110 | Accuracy |
| REDDIT-BINARY | Discussion threads | 2,000 | Accuracy |
| ogbg-molhiv | HIV inhibition | 41,127 | ROC-AUC |
- High variance: results on datasets with a few hundred graphs should be reported as mean and deviation over repeated cross-validation.
- Selection leakage: choosing hyperparameters on test folds inflates reported accuracy and has distorted published comparisons.
- Weak splits: random molecule splits overestimate generalization; a scaffold split better reflects new chemistry.
- Missing baselines: structure-agnostic models and WL kernels sometimes match complex GNNs and should always be included.
Explained without jargon
A graph is a set of dots joined by lines. A molecule fits this picture: atoms are dots and chemical bonds are lines. Graph classification looks at the whole drawing at once and gives it one label.
Imagine sorting many stick-figure toys into boxes by shape. The sorter does not care which stick was built first. It only cares how the pieces connect. Computers do the same with graphs, and they learn which connection patterns point to which label.
A typical use case
A pharmaceutical research group screens a library of 200,000 candidate compounds for liver toxicity before laboratory testing. Each compound is represented as a graph with atoms as nodes, carrying element type and charge, and bonds as edges, carrying bond type. The team trains a five-layer GIN with sum readout on about 12,000 compounds with known toxicity labels.
To avoid overly optimistic results, the data are divided with a scaffold split, so test molecules have core structures unseen in training. The model reaches a ROC-AUC of about 0.84 on this split, compared with 0.79 for a WL kernel baseline. Chemists then send only the top 5% of predicted safe compounds to assays, which cuts laboratory workload substantially while keeping most promising candidates in the pipeline.