Load

This tutorial shows how to load graphs from files in various formats and from existing collections of datasets, NetSets and Konect.

[1]:
from sknetwork.data import load_edge_list, load_graphml, load_netset, load_konect

TSV files

Loading a graph from a TSV file (list of edges).

[2]:
graph = load_edge_list('miserables.tsv')
adjacency = graph.adjacency
names = graph.names
[3]:
# Digraph
graph = load_edge_list('painters.tsv', directed=True)
adjacency = graph.adjacency
names = graph.names
[4]:
# Bigraph
graph = load_edge_list('movie_actor.tsv', bipartite=True)
biadjacency = graph.biadjacency
names_row = graph.names_row
names_col = graph.names_col

GraphML files

Loading a graph from a GraphML file.

[5]:
graph = load_graphml('miserables.graphml')
adjacency = graph.adjacency
names = graph.names
[6]:
# Digraph
graph = load_graphml('painters.graphml')
adjacency = graph.adjacency
names = graph.names

NetSet

Loading a graph from the NetSets collection.

[7]:
graph = load_netset('openflights')
adjacency = graph.adjacency
names = graph.names
[8]:
# to get all fields
graph
[8]:
{'adjacency': <3097x3097 sparse matrix of type '<class 'numpy.int64'>'
        with 36386 stored elements in Compressed Sparse Row format>,
 'names': array(['Goroka Airport', 'Madang Airport', 'Mount Hagen Kagamuga Airport',
        ..., 'Saumlaki/Olilit Airport', 'Tarko-Sale Airport',
        'Alashankou Bole (Bortala) airport'], dtype='<U65'),
 'meta': {'name': 'openflights',
  'description': 'Airports with daily number of flights between them.',
  'source': 'https://openflights.org'},
 'position': array([[145.39199829,  -6.08168983],
        [145.78900147,  -5.20707989],
        [144.29600525,  -5.82678986],
        ...,
        [131.30599976,  -7.98860979],
        [ 77.81809998,  64.93080139],
        [ 82.3       ,  44.895     ]])}
[9]:
# Digraph
graph = load_netset('wikivitals')
adjacency = graph.adjacency
names = graph.names
labels = graph.labels
[10]:
# Bigraph
graph = load_netset('cinema')
biadjacency = graph.biadjacency

Konect

Loading a graph from the Konect collection.

[11]:
# first check server availability!
# graph = load_konect('dolphins')
# adjacency = graph.adjacency