Introduction to Networks

Introduction to Network Analysis in Python

Eric Ma

Data Carpentry instructor and author of nxviz package

Networks!

  • Examples:

    • Social

    • Transportation

  • Model relationships between entities

Introduction to Network Analysis in Python

Networks!

  • Insights:

  • Important entities: influencers in social network

  • Pathfinding: most efficient transport path

  • Clustering: finding communities

Introduction to Network Analysis in Python

Network Structure

Two nodes

Introduction to Network Analysis in Python

Network Structure

Two nodes connected by an edge

Introduction to Network Analysis in Python

Network Structure

Graph with two nodes connected by an edge

Introduction to Network Analysis in Python

Network Structure

Graph with two nodes connected by an edge. The nodes are labeled 'Hugo' and 'Eric', and the edge connection is labeled 'Friendship'. Each node has 'id' and 'age' metadata attributes, and the edge has a 'date' metadata attribute.

Introduction to Network Analysis in Python

NetworkX API Basics

import networkx as nx

G = nx.Graph()
G.add_nodes_from([1, 2, 3])
G.nodes()
NodeView([1, 2, 3])
G.add_edge(1, 2)

G.edges()
EdgeView([(1, 2)])
Introduction to Network Analysis in Python

NetworkX API Basics

G.nodes[1]['label'] = 'blue'

G.nodes(data=True)
[(1, {'label': 'blue'}), (2, {}), (3, {})]
Introduction to Network Analysis in Python

NetworkX API Basics

nx.draw(G)

import matplotlib.pyplot as plt plt.show()

Node link diagram of a graph.

Introduction to Network Analysis in Python

Let's practice!

Introduction to Network Analysis in Python

Preparing Video For Download...