Network Science with Python and NetworkX Quick Start Guide
eBook - ePub

Network Science with Python and NetworkX Quick Start Guide

Explore and visualize network data effectively

  1. 190 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Network Science with Python and NetworkX Quick Start Guide

Explore and visualize network data effectively

Book details
Book preview
Table of contents
Citations

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

Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Yes, you can access Network Science with Python and NetworkX Quick Start Guide by Edward L. Platt in PDF and/or ePUB format, as well as other popular books in Computer Science & Data Processing. We have over one million books available in our catalogue for you to explore.

Information

Year
2019
ISBN
9781789950410
Edition
1

Social Networks and Going Viral

Network analysis is often used to understand the behavior of groups of people. Relationships within a group of people form a kind of network—a social network. Social networks are some of the longest-studied in network science, and provide some of the results most directly applicable to everyday life. This chapter will introduce you to the elementary results in social network analysis.
Topics in this chapter include the following:
  • 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

The defining feature of social networks is that nodes represent people. The networks themselves can represent anything from small informal friend groups to entire societies.
Edges in a social network represent a type of relationship between people. Often, this relationship is friendship or communication. However, it can also be something as abstract as the similarity in their video streaming behavior. Just imagine; you might never have met someone, but you could be the only two people in the world who enjoy watching videos of sleeping hippos. That is certainly a kind of relationship!
Many of the tools of network science come from the study of social networks in sociology. The sociologists, Jacob L. Moreno and Helen Hall Jennings, developed the techniques of sociometry, a precursor to modern social network analysis and network science (Moreno And Jennings, 1934).
Social networks deserve special attention because common human behaviors result in characteristic types of network structure. Also, the structure of a social network has important implications for social processes, including the following:
  • Finding job opportunities
  • The spread of ideas
  • The spread of disease
  • Health behaviors

Strong and weak ties

In social networks, not all relationships are created equal. You might cosign a loan application for your sibling, but probably not for your cousin's babysitter's dentist's chimney sweep. In sociology, the strength of a relationship is captured by the concept of tie strength. In this context, a tie is some kind of an interpersonal relationship, and the strength is any measure of how intense or intimate that relationship is.
In 1973, the sociologist Mark Granovetter described the importance of weak ties in bridging different communities. If all ties within a community are strong, then any ties between communities must be weak. He described this phenomenon as the strength of weak ties. By bridging different communities, weak ties make it possible to find information from distant parts of a network. But how do we measure tie strength?

Tie strength

One approach to measuring tie strength was described in Chapter 2, Working with Networks in NetworkX. This section will build on that example using the Zachary karate club network (1977). The code to load the network is reproduced from Chapter 2, Working with Networks in NetworkX, as follows:
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']]
By the definition of community, individuals in the same community are more likely to have common friends than those in different communities. So, as in Chapter 2, Working with Networks in NetworkX, the number of common friends can be used to construct a measure of tie strength as follows:
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)
The following code calculates the tie strength of each edge and stores it in strength:
strength = dict(
((v,w), tie_strength(G, v, w))
for v, w in G.edges())

Bridge span

Tie strength can also be quantified by considering the effect of removing an edge from the network. Nodes connected by an edge are always distance 1 apart (in an unweighted network). But if that edge is removed, its endpoints could be anywhere from distance 2 apart to entirely unconnected. This concept is captured by the bridge span, the network distance between an edge's endpoints if that edge is removed. Edges with large spans connect distant parts of a network, so they may be considered weak ties, despite playing an important role.
The following code calculates the span of each edge in the karate club network:
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

Let's look at the 10 strongest and 10 weakest edges in the karate club network. The following code prints these edges:
# 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

  1. Title Page
  2. Copyright and Credits
  3. Dedication
  4. About Packt
  5. Contributors
  6. Preface
  7. What is a Network?
  8. Working with Networks in NetworkX
  9. From Data to Networks
  10. Affiliation Networks
  11. The Small Scale - Nodes and Centrality
  12. The Big Picture - Describing Networks
  13. In-Between - Communities
  14. Social Networks and Going Viral
  15. Simulation and Analysis
  16. Networks in Space and Time
  17. Visualization
  18. Conclusion
  19. Appendix
  20. Other Books You May Enjoy