liveBook · Manning

Subgraph

As explained in Graph Neural Networks in Action

A subgraph is a graph formed from a subset of the nodes and edges of another graph.

A subgraph is a graph formed from selected nodes and their corresponding edges in a larger graph. It makes large or disconnected graphs easier to process, inspect, and model. Creating one requires filtering edges that leave the selected node set, relabeling nodes consistently, and keeping features, labels, and original identifiers aligned. section 3.1.1 section 8.3

A practical subgraph-construction pipeline is:

  • Select nodes using an index range, domain rule, connected-component analysis, or graph-sampling strategy. section 3.1.1 section 3.6
  • Filter the edge list so that retained edges connect only retained nodes. section 3.1.1
  • Relabel retained nodes, then slice and reassign their features and labels using the new ordering. section 3.1.1
  • Preserve mappings to original node indices when downstream work needs identifiers such as product categories or SKUs. section 3.1.1

Reducing a product graph

For the Amazon Products graph, selecting the first 10,000 node indices creates a smaller working graph from 2.5 million nodes and 61.9 million co-purchase edges. PyTorch Geometric's subgraph utility returns filtered edges and can relabel nodes; features and labels are then sliced into a new graph object. section 3.1.1

Figure 8.12 The full graph, with its large connected component in the middle, surrounded by many smaller components. For our example, we’ll use only the nodes in the large connected component.
figure

A graph visualization contrasts one large connected component with many small components, motivating subgraph extraction before analysis. section 8.3.3

How Graph Neural Networks in Action covers it

How deep it goes
Explains selection, edge filtering, relabeling, feature-label alignment, and identifier recovery, but defers broader subgraph strategies to later treatment.
Examples
Demonstrates Amazon product reduction and isolation of a social graph's largest connected component for visualization and degree analysis.
What you can do after
Build it from scratch with PyTorch Geometric or NetworkX while maintaining valid edges, aligned attributes, and recoverable original indices.
How it connects
Connects graph nodes and edges with edge lists, node features, labels, masks, connected components, graph sampling, GCNs, and GraphSAGE.

Also explained in

Compare how 2 books explain subgraph →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Graph Neural Networks in Action. The section links point to the parts of the book it draws on.