Hi,šŸ‘‹ we have updated the app and fixed multiple bugs. We are lacking funds, request to free user not to use Adblock. Ads are non intrusive. 😊

@_avichawla: - Google Maps uses graph ML to...

@_avichawla
8 views Dec 12, 2025
1
- Google Maps uses graph ML to predict ETA
- Netflix uses graph ML in recommendation
- Spotify uses graph ML in recommendation
- Pinterest uses graph ML in recommendation

Here are 6 must-know ways for graph feature engineering (with code):
2
Like images, text, and tabular datasets have features, so do graph datasets.

This means when building models on graph datasets, we can engineer these features to achieve better performance.

Let's discuss some feature engineering techniques below!
Media image
3
First, let’s create a dummy social networking graph dataset with accounts and followers (which will also be accounts).

We create the two DataFrames shown below, an accounts DataFrame and a followers DataFrame.

Check this codešŸ‘‡
Media image
4
The above data is tabular, but we need to convert this into a graph format.

To do this, we use the networkx framework as follows:

• Initialize a graphĀ G.
• AddĀ nodes from theĀ accountsĀ DF.
• Added edges between the nodes using theĀ followers'Ā DF.

Here's the codešŸ‘‡
Media image
5
This produces the following graph.

Next, let's cover the 6 graph feature engineering techniques.
Media image
6
1-3) Node degree

In a directed graph, there are two types of degrees:

• In-Degree:Ā The number of incoming edges (followers) a node has.
• Out-Degree:Ā The number of outgoing edges (followings) a node has.
7
Here’s how we can compute them using NetworkX:

• in_degree(x)Ā counts edges directed toward the nodeĀ x.
• out_degree(x)Ā counts edges directed away from the nodeĀ x.
• degree(x)Ā is the sum of the in-degree and out-degree of nodeĀ x.

Check this codešŸ‘‡
Media image
8
These features are now part of the accounts DataFrame.

Check thisšŸ‘‡
Media image
9
4-6) Node centrality

Node degree features capture connectedness but fail to capture the influence of those connections.

For instance, a user can have many online friends just because they send friend requests to everyone.

Centrality features handle this.
10
4) Betweenness centrality

This measures how often a node appears on the shortest paths between other nodes.

If a node often acts as a ā€œbridgeā€ between other nodes, it plays a key role in facilitating information flow.

Here's the codešŸ‘‡
Media image
11
5) Closeness centrality

This indicates how close a node is to all other nodes in the network based on the shortest paths.

To compute closeness centrality for a node v, we sum the shortest path length from v to all other nodes and take its reciprocal.

Here's the codešŸ‘‡
Media image
12
6) Eigenvector centrality

If a node is connected to other influential nodes, it amplifies its own influence.

It helps identify nodes that are influential not only due to their direct ties but also due to their connections with other influential nodes.

Here's the codešŸ‘‡
Media image
13
PyTorch Geometric is a PyTorch extension specifically developed for building graph-based neural networks.

It has an intuitive API that facilitates inspecting and analyzing graphs and building ML models on graph-based datasets.

Open-source with 22k+ stars!
Media image
Actions
Visual Editor Carousel Maker NEW
Update Thread
What You Can Do
  • Download as PDF
  • Save to Notion
  • Export as Markdown
  • Visual Editor
  • LinkedIn & Instagram Carousel Maker
Create Free Account

Includes 7-day Premium trial