Chapter 21. Network Analysis
Your connections to all the things around you literally define who you are.
Aaron O’Connell
Many interesting data problems can be fruitfully thought of in terms of networks, consisting of nodes of some type and the edges that join them.
For instance, your Facebook friends form the nodes of a network whose edges are friendship relations. A less obvious example is the World Wide Web itself, with each web page a node, and each hyperlink from one page to another an edge.
Facebook friendship is mutual—if I am Facebook friends with you than necessarily you are friends with me. In this case, we say that the edges are undirected. Hyperlinks are not—my website links to whitehouse.gov, but (for reasons inexplicable to me) whitehouse.gov refuses to link to my website. We call these types of edges directed. We’ll look at both kinds of networks.
Betweenness Centrality
In Chapter 1, we computed the key connectors in the DataSciencester network by counting the number of friends each user had. Now we have enough machinery to look at other approaches. Recall that the network (Figure 21-1) comprised users:
users
=
[
{
"id"
:
0
,
"name"
:
"Hero"
},
{
"id"
:
1
,
"name"
:
"Dunn"
},
{
"id"
:
2
,
"name"
:
"Sue"
},
{
"id"
:
3
,
"name"
:
"Chi"
},
{
"id"
:
4
,
"name"
:
"Thor"
},
{
"id"
:
5
,
"name"
:
"Clive"
},
{
"id"
:
6
,
"name"
:
"Hicks"
},
{
"id"
:
7
,
"name"
:
"Devin"
},
{
"id"
:
8
,
"name"
:
"Kate"
},
{
"id"
:
9
,
"name"
:
"Klein"
}
]
and friendships:
friendships
=
[(
0
,
1
),
(
0
,
2
),
(
1
,
2
),
(
1
Get Data Science from Scratch now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.