Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Apprendre Graph Feature Representation | Foundations of Graph Machine Learning
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
Graph Theory for Machine Learning with Python

bookGraph Feature Representation

When working with graphs in machine learning, you often need to describe more than just the connections between nodes. Each node or edge can have associated information, called features or attributes, that provides extra context for learning tasks. Node features might represent properties like age, gender, or occupation in a social network, or gene expression levels in a biological network. Edge features could capture the strength of a relationship, timestamps, or types of interaction. Including these features allows graph machine learning models to make more informed predictions, such as classifying nodes, predicting links, or clustering similar entities.

To use these features in graph ML, you must store them in a way that algorithms and models can access. In Python, the networkx library provides a flexible way to attach attributes to both nodes and edges. This makes it easy to build rich graph structures that reflect real-world data.

123456789101112131415161718192021
import networkx as nx # Create a simple graph G = nx.Graph() # Add nodes with attributes G.add_node(1, label="Person", age=25) G.add_node(2, label="Person", age=30) G.add_node(3, label="Company", industry="Tech") # Add edges with attributes G.add_edge(1, 2, relation="friends", since=2015) G.add_edge(1, 3, relation="works_at", since=2020) # Access node attributes print(G.nodes[1]["label"]) # Output: Person print(G.nodes[3]["industry"]) # Output: Tech # Access edge attributes print(G.edges[(1, 2)]["relation"]) # Output: friends print(G.edges[(1, 3)]["since"]) # Output: 2020
copy
Note
Study More

In social networks, common node features include user demographics, interests, and activity levels. In biological networks, nodes may have attributes like protein function, gene expression, or cellular location. Edge features might include interaction types, binding strengths, or communication frequency.

question mark

Why are node features important for machine learning on graphs?

Select the correct answer

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 1. Chapitre 3

Demandez à l'IA

expand

Demandez à l'IA

ChatGPT

Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion

bookGraph Feature Representation

Glissez pour afficher le menu

When working with graphs in machine learning, you often need to describe more than just the connections between nodes. Each node or edge can have associated information, called features or attributes, that provides extra context for learning tasks. Node features might represent properties like age, gender, or occupation in a social network, or gene expression levels in a biological network. Edge features could capture the strength of a relationship, timestamps, or types of interaction. Including these features allows graph machine learning models to make more informed predictions, such as classifying nodes, predicting links, or clustering similar entities.

To use these features in graph ML, you must store them in a way that algorithms and models can access. In Python, the networkx library provides a flexible way to attach attributes to both nodes and edges. This makes it easy to build rich graph structures that reflect real-world data.

123456789101112131415161718192021
import networkx as nx # Create a simple graph G = nx.Graph() # Add nodes with attributes G.add_node(1, label="Person", age=25) G.add_node(2, label="Person", age=30) G.add_node(3, label="Company", industry="Tech") # Add edges with attributes G.add_edge(1, 2, relation="friends", since=2015) G.add_edge(1, 3, relation="works_at", since=2020) # Access node attributes print(G.nodes[1]["label"]) # Output: Person print(G.nodes[3]["industry"]) # Output: Tech # Access edge attributes print(G.edges[(1, 2)]["relation"]) # Output: friends print(G.edges[(1, 3)]["since"]) # Output: 2020
copy
Note
Study More

In social networks, common node features include user demographics, interests, and activity levels. In biological networks, nodes may have attributes like protein function, gene expression, or cellular location. Edge features might include interaction types, binding strengths, or communication frequency.

question mark

Why are node features important for machine learning on graphs?

Select the correct answer

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 1. Chapitre 3
some-alt