Network Science with Python and NetworkX Quick Start Guide
Explore and visualize network data effectively
- 190 pages
- English
- ePUB (mobile friendly)
- Available on iOS & Android
Network Science with Python and NetworkX Quick Start Guide
Explore and visualize network data effectively
About This Book
Manipulate and analyze network data with the power of Python and NetworkX
Key Features
- Understand the terminology and basic concepts of network science
- Leverage the power of Python and NetworkX to represent data as a network
- Apply common techniques for working with network data of varying sizes
Book Description
NetworkX is a leading free and open source package used for network science with the Python programming language. NetworkX can track properties of individuals and relationships, find communities, analyze resilience, detect key network locations, and perform a wide range of important tasks. With the recent release of version 2, NetworkX has been updated to be more powerful and easy to use.
If you're a data scientist, engineer, or computational social scientist, this book will guide you in using the Python programming language to gain insights into real-world networks. Starting with the fundamentals, you'll be introduced to the core concepts of network science, along with examples that use real-world data and Python code. This book will introduce you to theoretical concepts such as scale-free and small-world networks, centrality measures, and agent-based modeling. You'll also be able to look for scale-free networks in real data and visualize a network using circular, directed, and shell layouts.
By the end of this book, you'll be able to choose appropriate network representations, use NetworkX to build and characterize networks, and uncover insights while working with real-world systems.
What you will learn
- Use Python and NetworkX to analyze the properties of individuals and relationships
- Encode data in network nodes and edges using NetworkX
- Manipulate, store, and summarize data in network nodes and edges
- Visualize a network using circular, directed and shell layouts
- Find out how simulating behavior on networks can give insights into real-world problems
- Understand the ongoing impact of network science on society, and its ethical considerations
Who this book is for
If you are a programmer or data scientist who wants to manipulate and analyze network data in Python, this book is perfect for you. Although prior knowledge of network science is not necessary, some Python programming experience will help you understand the concepts covered in the book easily.
Frequently asked questions
Information
Social Networks and Going Viral
- Social networks: The history of social networks in network science
- Strong and weak ties: How to interpret and quantify the intensity of relationships
- The small world problem: Understanding how very large networks can be spanned by relatively short paths
- Contagion: How information, diseases, and anything else spreads over networks
Social networks
- Finding job opportunities
- The spread of ideas
- The spread of disease
- Health behaviors
Strong and weak ties
Tie strength
G = nx.karate_club_graph()
# Annotate with splinter club label
member_club = [
0, 0, 0, 0, 0, 0, 0, 0, 1, 1,
0, 0, 0, 0, 1, 1, 0, 0, 1, 0,
1, 0, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1]
nx.set_node_attributes(G, dict(enumerate(member_club)), 'club')
# Find internal and external edges
internal = [
(v, w) for v, w in G.edges
if G.nodes[v]['club'] == G.nodes[w]['club']]
external = [
(v, w) for v, w in G.edges
if G.nodes[v]['club'] != G.nodes[w]['club']]
def tie_strength(G, v, w):
# Get neighbors of nodes v and w in G
v_neighbors = set(G.neighbors(v))
w_neighbors = set(G.neighbors(w))
# Return size of the set intersection
return 1 + len(v_neighbors & w_neighbors)
strength = dict(
((v,w), tie_strength(G, v, w))
for v, w in G.edges())
Bridge span
def bridge_span(G):
# Get list of edges
edges = G.edges()
# Copy G
G = nx.Graph(G)
# Create result dict
result = dict()
for v, w in edges:
# Temporarily remove edge
G.remove_edge(v, w)
# Find distance with edge removed
try:
d = nx.shortest_path_length(G, v, w)
result[(v, w)] = d
except nx.NetworkXNoPath:
result[(v, w)] = float('inf')
# Restore edge
G.add_edge(v, w)
return result
span = bridge_span(G)
Comparing strength and span
# Order edges by tie strength
ordered_edges = sorted(strength.items(), key=lambda x: x[1])
print('Edge\t Strength\tSpan\tInternal')
# Print 10 strongest
for e, edge_strength in ordered_edges[:10]:
print('{:10}{}\t\t{}\t{}'.format(
str(e), edge_strength, span[e], G.edges[e]['internal']))
print('...')
# Print 10 weakest
for e, edge_strength in ordered_edges[-10:]:
print('{:10}{}\t\t{}\t{}'.format(
str(e), edge_strength, span[e], G.edges[e]['internal']))
Edge Strength Span Internal
(0, 11) 1 inf internal
(0, 31) 1 3 external
(1, 30) 1 3 external
(2, 9) 1 3 external
(2, 27) 1 3 external
(2, 28) 1 3 external
(9, 33) 1 3 internal
(13, 33) 1 3 external
(19...
Table of contents
- Title Page
- Copyright and Credits
- Dedication
- About Packt
- Contributors
- Preface
- What is a Network?
- Working with Networks in NetworkX
- From Data to Networks
- Affiliation Networks
- The Small Scale - Nodes and Centrality
- The Big Picture - Describing Networks
- In-Between - Communities
- Social Networks and Going Viral
- Simulation and Analysis
- Networks in Space and Time
- Visualization
- Conclusion
- Appendix
- Other Books You May Enjoy