Non-Euclidean data has relational or geometric structure for which straight-line distance is not the defining notion of proximity. Graphs express proximity through nodes, edges, and neighborhood structure rather than a regular grid or fixed spatial layout. section 11.3 section 11.3.1
Common forms and learning tasks include:
- Graphs representing road networks, social networks, web pages, and molecular structures. section 11.3
- Point clouds, molecules, and manifolds with underlying geometric structure. section 11.3
- Node classification, link prediction, and community detection after graph embedding or representation learning. section 11.3
A soccer-player graph
Represent each player, club, and nationality as a node. Connect a player to a club with a plays_for relationship and to a nationality with a belongs_to relationship. The resulting graph captures relationships that a table of independent feature vectors does not express directly. section 11.3
Why road networks need relational structure
For estimated travel time, congestion on one road segment can influence neighboring segments. Treating segments as independent samples misses this dependency, whereas graph machine learning can use the network connections. section 11.3.1
Listing 11.1 Converting tabular data to a graph
import pandas as pd
import networkx as nx
import matplotlib.pyplot as plt
data={'Player':['L. Messi','R. Lewandowski','C. Ronaldo','Neymar Jr','K.
Mbappé','E.Haaland','H. Kane','Luka Modrić','L. Goretzka','M. Salah'],
'Age':[36,34,38,22,24,35,29,37,28,31],
'Nationality':['Argentina','Poland','Portugal','Brazil','France','Norway',
'England','Croatia','Germany','Egypt'],
'Club':['Inter Miami','Barcelona','Al-Nassr','Al-Hilal ','PSG','Manchester
City','Tottenham Hotspur','Real Madrid','Bayern Munich','Liverpool'],
'League':['Major League Soccer ','Spain Primera Division','Saudi Arabia
League','Saudi Arabia League','French Ligue 1','English Premier
League','English Premier League','Spain Primera Division','German 1.
Bundesliga','English Premier League']}
df=pd.DataFrame.from_dict(data)
Inspect a tabular soccer dataset before converting player, club, and nationality relationships into graph edges. section 11.3
Listing 11.2 Node embedding using GCN
import numpy as np from sklearn.preprocessing import StandardScaler from sklearn.decomposition import PCA from sklearn.pipeline import Pipeline import torch import torch.nn.functional as F from torch_geometric.datasets import Planetoid from torch_geometric.nn import GCNConv from torch_geometric.utils import to_networkx
Explore a PyTorch Geometric workflow for producing node embeddings with a graph convolutional network. section 11.3.1
