5 Thmodule
5 Thmodule
Chapter 10
Mining Social-Network
Graphs
355
356 CHAPTER 10. MINING SOCIAL-NETWORK GRAPHS
A B D E
G F
the third edge exists is thus 9/16 = .563. This fraction is considerably greater
than the .368 expected value for that fraction. We conclude that Fig. 10.1 does
indeed exhibit the locality expected in a social network. ✷
Telephone Networks
Here the nodes represent phone numbers, which are really individuals. There
is an edge between two nodes if a call has been placed between those phones
in some fixed period of time, such as last month, or “ever.” The edges could
be weighted by the number of calls made between these phones during the
period. Communities in a telephone network will form from groups of people
that communicate frequently: groups of friends, members of a club, or people
working at the same company, for example.
Email Networks
The nodes represent email addresses, which are again individuals. An edge
represents the fact that there was at least one email in at least one direction
between the two addresses. Alternatively, we may only place an edge if there
were emails in both directions. In that way, we avoid viewing spammers as
“friends” with all their victims. Another approach is to label edges as weak or
strong. Strong edges represent communication in both directions, while weak
edges indicate that the communication was in one direction only. The com-
munities seen in email networks come from the same sorts of groupings we
mentioned in connection with telephone networks. A similar sort of network
involves people who text other people through their cell phones.
Collaboration Networks
Nodes represent individuals who have published research papers. There is an
edge between two individuals who published one or more papers jointly. Option-
ally, we can label edges by the number of joint publications. The communities
in this network are authors working on a particular topic.
An alternative view of the same data is as a graph in which the nodes are
papers. Two papers are connected by an edge if they have at least one author
in common. Now, we form communities that are collections of papers on the
same topic.
There are several other kinds of data that form two networks in a similar
way. For example, we can look at the people who edit Wikipedia articles and
the articles that they edit. Two editors are connected if they have edited an
10.1. SOCIAL NETWORKS AS GRAPHS 359
article in common. The communities are groups of editors that are interested
in the same subject. Dually, we can build a network of articles, and connect
articles if they have been edited by the same person. Here, we get communities
of articles on similar or related subjects.
In fact, the data involved in Collaborative filtering, as was discussed in
Chapter 9, often can be viewed as forming a pair of networks, one for the
customers and one for the products. Customers who buy the same sorts of
products, e.g., science-fiction books, will form communities, and dually, prod-
ucts that are bought by the same customers will form communities, e.g., all
science-fiction books.
T1 W1
U1 T2 W2
U2 T3 W3
T4
Figure 10.2: A tripartite graph representing users, tags, and Web pages
that the graph does not tell us a detail that could be important: who placed
which tag on which page? To represent such ternary information would require
a more complex representation, such as a database relation with three columns
corresponding to users, tags, and pages. ✷
! (e) What we called the dual is not a true dual, because applying the con-
struction to G′ does not necessarily yield a graph isomorphic to G. Give
an example graph G where the dual of G′ is isomorphic to G and another
example where the dual of G′ is not isomorphic to G.
the clusters to which their two nodes belong. The choices would be random,
because all distances represented by an edge are the same.
Example 10.3 : Consider again the graph of Fig. 10.1, repeated here as Fig.
10.3. First, let us agree on what the communities are. At the highest level,
it appears that there are two communities {A, B, C} and {D, E, F, G}. How-
ever, we could also view {D, E, F } and {D, F, G} as two subcommunities of
{D, E, F, G}; these two subcommunities overlap in two of their members, and
thus could never be identified by a pure clustering algorithm. Finally, we could
consider each pair of individuals that are connected by an edge as a community
of size 2, although such communities are uninteresting.
A B D E
G F
The problem with hierarchical clustering of a graph like that of Fig. 10.3 is
that at some point we are likely to chose to combine B and D, even though
they surely belong in different clusters. The reason we are likely to combine B
and D is that D, and any cluster containing it, is as close to B and any cluster
containing it, as A and C are to B. There is even a 1/9 probability that the
first thing we do is to combine B and D into one cluster.
There are things we can do to reduce the probability of error. We can
run hierarchical clustering several times and pick the run that gives the most
coherent clusters. We can use a more sophisticated method for measuring the
distance between clusters of more than one node, as discussed in Section 7.2.3.
But no matter what we do, in a large graph with many communities there is a
significant chance that in the initial phases we shall use some edges that connect
two nodes that do not belong together in any large community. ✷
possible, we don’t do much better; we could thereby pick any pair of nodes not
connected by an edge, e.g., E and G in Fig. 10.3.
However, suppose we do get two suitable starting nodes, such as B and F .
We shall then assign A and C to the cluster of B and assign E and G to the
cluster of F . But D is as close to B as it is to F , so it could go either way, even
though it is “obvious” that D belongs with F .
If the decision about where to place D is deferred until we have assigned
some other nodes to the clusters, then we shall probably make the right decision.
For instance, if we assign a node to the cluster with the shortest average distance
to all the nodes of the cluster, then D should be assigned to the cluster of F , as
long as we do not try to place D before any other nodes are assigned. However,
in large graphs, we shall surely make mistakes on some of the first nodes we
place. ✷
10.2.3 Betweenness
Since there are problems with standard clustering methods, several specialized
clustering techniques have been developed to find communities in social net-
works. In this section we shall consider one of the simplest, based on finding
the edges that are least likely to be inside a community.
Define the betweenness of an edge (a, b) to be the number of pairs of nodes
x and y such that the edge (a, b) lies on the shortest path between x and y.
To be more precise, since there can be several shortest paths between x and y,
edge (a, b) is credited with the fraction of those shortest paths that include the
edge (a, b). As in golf, a high score is bad. It suggests that the edge (a, b) runs
between two different communities; that is, a and b do not belong to the same
community.
Example 10.5 : In Fig. 10.3 the edge (B, D) has the highest betweenness, as
should surprise no one. In fact, this edge is on every shortest path between
any of A, B, and C to any of D, E, F , and G. Its betweenness is therefore
3 × 4 = 12. In contrast, the edge (D, F ) is on only four shortest paths: those
from A, B, C, and D to F . ✷
Edges between levels are called DAG edges (“DAG” stands for directed,
acyclic graph). Each DAG edge will be part of at least one shortest path
from root X. If there is a DAG edge (Y, Z), where Y is at the level above Z
(i.e., closer to the root), then we shall call Y a parent of Z and Z a child of Y ,
although parents are not necessarily unique in a DAG as they would be in a
tree.
1
E
1 1
Level 1 D F
1
Level 2 B G 2
1 1
Level 3 A C
The second step of the GN algorithm is to label each node by the number of
shortest paths that reach it from the root. Start by labeling the root 1. Then,
from the top down, label each node Y by the sum of the labels of its parents.
Example 10.7 : In Fig. 10.4 are the labels for each of the nodes. First, label
the root E with 1. At level 1 are the nodes D and F . Each has only E as a
parent, so they too are labeled 1. Nodes B and G are at level 2. B has only
D as a parent, so B’s label is the same as the label of D, which is 1. However,
G has parents D and F , so its label is the sum of their labels, or 2. Finally, at
level 3, A and C each have only parent B, so their labels are the label of B,
which is 1. ✷
The third and final step is to calculate for each edge e the sum over all nodes
Y of the fraction of shortest paths from the root X to Y that go through e.
This calculation involves computing this sum for both nodes and edges, from
the bottom. Each node other than the root is given a credit of 1, representing
the shortest path to that node. This credit may be divided among nodes and
10.2. CLUSTERING OF SOCIAL-NETWORK GRAPHS 365
edges above, since there could be several different shortest paths to the node.
The rules for the calculation are as follows:
1. Each leaf in the DAG (a leaf is a node with no DAG edges to nodes at
levels below) gets a credit of 1.
2. Each node that is not a leaf gets a credit equal to 1 plus the sum of the
credits of the DAG edges from that node to the level below.
3. A DAG edge e entering node Z from the level above is given a share of the
credit of Z proportional to the fraction of shortest paths from the root to
Z that go through e. Formally, let the parents of Z be Y1 , Y2 , . . . , Yk . Let
pi be the number of shortest paths from the root to Yi ; this number was
computed in Step 2 and is illustrated by the labels in Fig. 10.4. ThenP the
credit for the edge (Yi , Z) is the credit of Z times pi divided by kj=1 pj .
After performing the credit calculation with each node as the root, we sum
the credits for each edge. Then, since each shortest path will have been discov-
ered twice – once when each of its endpoints is the root – we must divide the
credit for each edge by 2.
Example 10.8 : Let us perform the credit calculation for the BFS presentation
of Fig. 10.4. We shall start from level 3 and proceed upwards. First, A and C,
being leaves, get credit 1. Each of these nodes have only one parent, so their
credit is given to the edges (B, A) and (B, C), respectively.
D F
3 B G 1
1 1
1 A C 1
Now, let us proceed to level 1. B has only one parent, D, so the edge
(D, B) gets the entire credit of B, which is 3. However, G has two parents, D
and F . We therefore need to divide the credit of 1 that G has between the edges
(D, G) and (F, G). In what proportion do we divide? If you examine the labels
of Fig. 10.4, you see that both D and F have label 1, representing the fact that
there is one shortest path from E to each of these nodes. Thus, we give half
the credit of G to each of these edges; i.e., their credit is each 1/(1 + 1) = 0.5.
Had the labels of D and F in Fig. 10.4 been 5 and 3, meaning there were five
shortest paths to D and only three to F , then the credit of edge (D, G) would
have been 5/8 and the credit of edge (F, G) would have been 3/8.
4.5 1.5
4.5 D F 1.5
3 0.5 0.5
3 B G 1
1 1
1 A C 1
Now, we can assign credits to the nodes at level 1. D gets 1 plus the credits
of the edges entering it from below, which are 3 and 0.5. That is, the credit of D
is 4.5. The credit of F is 1 plus the credit of the edge (F, G), or 1.5. Finally, the
edges (E, D) and (E, F ) receive the credit of D and F , respectively, since each
of these nodes has only one parent. These credits are all shown in Fig. 10.6.
The credit on each of the edges in Fig. 10.6 is the contribution to the be-
tweenness of that edge due to shortest paths from E. For example, this contri-
bution for the edge (E, D) is 4.5. ✷
it is not defined for pairs of nodes that are unconnected by an edge, and might
not satisfy the triangle inequality even when defined. However, we can cluster
by taking the edges in order of increasing betweenness and add them to the
graph one at a time. At each step, the connected components of the graph
form some clusters. The higher the betweenness we allow, the more edges we
get, and the larger the clusters become.
More commonly, this idea is expressed as a process of edge removal. Start
with the graph and all its edges; then remove edges with the highest between-
ness, until the graph has broken into a suitable number of connected compo-
nents.
Example 10.9 : Let us start with our running example, the graph of Fig. 10.1.
We see it with the betweenness for each edge in Fig. 10.7. The calculation of
the betweenness will be left to the reader. The only tricky part of the count
is to observe that between E and G there are two shortest paths, one going
through D and the other through F . Thus, each of the edges (D, E), (E, F ),
(D, G), and (G, F ) are credited with half a shortest path.
5 12 4.5
A B D E
1 5 4
4.5 1.5
C
G F
1.5
A B D E
G F
Figure 10.8: All the edges with betweenness 4 or more have been removed
of the following nodes that pass through each of the edges. (a) A (b) B.
Exercise 10.2.2 : Using symmetry, the calculations of Exercise 10.2.1 are all
you need to compute the betweenness of each edge. Do the calculation.
Exercise 10.2.3 : Using the betweenness values from Exercise 10.2.2, deter-
mine reasonable candidates for the communities in Fig. 10.9 by removing all
edges with a betweenness above some threshold.
B C
H D
I G E F
Example 10.10 : Suppose our graph has nodes numbered 1, 2, . . . , n and there
is an edge between two nodes i and j unless i and j have the same remain-
der when divided by k. Then the fraction of possible edges that are actually
present is approximately (k − 1)/k. There are many cliques of size k, of which
{1, 2, . . . , k} is but one example.
Yet there are no cliques larger than k. To see why, observe that any set of
k + 1 nodes has two that leave the same remainder when divided by k. This
point is an application of the “pigeonhole principle.” Since there are only k
different remainders possible, we cannot have distinct remainders for each of
k + 1 nodes. Thus, no set of k + 1 nodes can be a clique in this graph. ✷
by selecting some nodes and including all edges. In this context, we only require that there
be edges between any pair of nodes on different sides. It is also possible that some nodes on
the same side are connected by edges as well.
10.3. DIRECT DISCOVERY OF COMMUNITIES 371
of the baskets in which all those items appear form an instance of Ks,t .
1 a
2 b
3 c
4 d
Example 10.11 : Recall the bipartite graph of Fig. 8.1, which we repeat here as
Fig. 10.10. The left side is the nodes {1, 2, 3, 4} and the right side is {a, b, c, d}.
The latter are the baskets, so basket a consists of “items” 1 and 4; that is,
a = {1, 4}. Similarly, b = {2, 3}, c = {1} and d = {3}.
If s = 2 and t = 1, we must find itemsets of size 1 that appear in at least
two baskets. {1} is one such itemset, and {3} is another. However, in this tiny
example there are no itemsets for larger, more interesting values of s and t,
such as s = t = 2. ✷
nodes on the right is i dti . The value of this sum depends on the di ’s, of
P
Example 10.12 : Suppose there are only two nodes, t = 2, and the average
degree of the nodes is 4. Then d1 + d2 = 8, and the sum of interest is d21 + d22 .
is 62 + 22 = 15 + 1 = 16. ✷
Thus, in what follows, we shall assume that all nodes have the average degree
d. So doing minimizes the total contribution to the counts for the itemsets, and
thus makes it least likely that there will be a frequent itemset (itemset with
with support s or more) of size t. Observe the following:
• The total contribution of the n nodes on the right to the counts of the
itemsets of size t is n dt .
n(d/n)t ≥ s
That is, if there is a community with n nodes on each side, the average degree
of the nodes is d, and n(d/n)t ≥ s, then this community is guaranteed to have
a complete bipartite subgraph Ks,t . Moreover, we can find the instance of Ks,t
efficiently, using the methods of Chapter 6, even if this small community is
embedded in a much larger graph. That is, we can treat all nodes in the entire
graph as baskets and as items, and run A-priori or one of its improvements on
the entire graph, looking for sets of t items with support s.
10.3. DIRECT DISCOVERY OF COMMUNITIES 373
Example 10.13 : Suppose there is a community with 100 nodes on each side,
and the average degree of nodes is 50; i.e., half the possible edges exist. This
community will have an instance of Ks,t , provided 100(1/2)t ≥ s. For example,
if t = 2, then s can be as large as 25. If t = 3, s can be 11, and if t = 4, s can
be 6.
Unfortunately, the approximation we made gives us a bound on s that is a
little too high. If we revert to the original formula n dt / nt ≥ s, we see that
100 × 50 × 49 × 48 × 47
≥s
100 × 99 × 98 × 97
The expression on the left is not 6, but only 5.87. However, if the average
support for an itemset of size 4 is 5.87, then it is impossible that all those
itemsets have support 5 or less. Thus, we can be sure that at least one itemset
of size 4 has support 6 or more, and an instance of K6.4 exists in this community.
✷
(a) s = 1 and t = 3.
(b) s = 2 and t = 2.
(c) s = 2 and t = 3.
(a) n = 20 and d = 5.
Example 10.14 : Recall our running example of the graph in Fig. 10.1. There,
it is evident that the best partition puts {A, B, C} in one set and {D, E, F, G}
in the other. The cut consists only of the edge (B, D) and is of size 1. No
nontrivial cut can be smaller.
A B D E
H G F
Best cut
Smallest
cut
Figure 10.11: The smallest cut might not be the best cut
In Fig. 10.11 is a variant of our example, where we have added the node
H and two extra edges, (H, C) and (C, G). If all we wanted was to minimize
the size of the cut, then the best choice would be to put H in one set and all
the other nodes in the other set. But it should be apparent that if we reject
10.4. PARTITIONING OF GRAPHS 375
partitions where one set is too small, then the best we can do is to use the
cut consisting of edges (B, D) and (C, G), which partitions the graph into two
equal-sized sets {A, B, C, H} and {D, E, F, G}. ✷
Example 10.15 : Again consider the graph of Fig. 10.11. If we choose S = {H}
and T = {A, B, C, D, E, F, G}, then Cut (S, T ) = 1. Vol(S) = 1, because there
is only one edge connected to H. On the other hand, Vol(T ) = 11, because all
the edges have at least one end at a node of T . Thus, the normalized cut for
this partition is 1/1 + 1/11 = 1.09.
Now, consider the preferred cut for this graph consisting of the edges (B, D)
and (C, G). Then S = {A, B, C, H} and T = {D, E, F, G}. Cut (S, T ) = 2,
Vol (S) = 6, and Vol(T ) = 7. The normalized cut for this partition is thus only
2/6 + 2/7 = 0.62. ✷
A B D E
G F
Example 10.16 : We repeat our running example graph in Fig. 10.12. Its
adjacency matrix appears in Fig. 10.13. Note that the rows and columns cor-
respond to the nodes A, B, . . . , G in that order. For example, the edge (B, D)
is reflected by the fact that the entry in row 2 and column 4 is 1 and so is the
entry in row 4 and column 2. ✷
0 1 1 0 0 0 0
1 0 1 1 0 0 0
1 1 0 0 0 0 0
0 1 0 0 1 1 1
0 0 0 1 0 1 0
0 0 0 1 1 0 1
0 0 0 1 0 1 0
The second matrix we need is the degree matrix for a graph. This graph has
nonzero entries only on the diagonal. The entry for row and column i is the
degree of the ith node.
Example 10.17 : The degree matrix for the graph of Fig. 10.12 is shown in
Fig. 10.14. We use the same order of the nodes as in Example 10.16. For
instance, the entry in row 4 and column 4 is 4 because node D has edges to
four other nodes. The entry in row 4 and column 5 is 0, because that entry is
not on the diagonal. ✷
2 0 0 0 0 0 0
0 3 0 0 0 0 0
0 0 2 0 0 0 0
0 0 0 4 0 0 0
0 0 0 0 2 0 0
0 0 0 0 0 3 0
0 0 0 0 0 0 2
Suppose our graph has adjacency matrix A and degree matrix D. Our third
matrix, called the Laplacian matrix, is L = D − A, the difference between the
degree matrix and the adjacency matrix. That is, the Laplacian matrix L has
the same entries as D on the diagonal. Off the diagonal, at row i and column j,
L has −1 if there is an edge between nodes i and j and 0 if not.
Example 10.18 : The Laplacian matrix for the graph of Fig. 10.12 is shown
in Fig. 10.15. Notice that each row and each column sums to zero, as must be
the case for any Laplacian matrix. ✷
10.4. PARTITIONING OF GRAPHS 377
2 -1 -1 0 0 0 0
-1 3 -1 -1 0 0 0
-1 -1 2 0 0 0 0
0 -1 0 4 -1 -1 -1
0 0 0 -1 2 -1 0
0 0 0 -1 -1 3 -1
0 0 0 -1 0 -1 2
Pn
1. The length of x is 1; that is i=1 x2i = 1.
Moreover, the value of x that achieves this minimum is the second eigenvector.
When L is a Laplacian matrix for an n-node graph, we know something
more. The eigenvector associated with the smallest eigenvalue is 1. Thus, if x
378 CHAPTER 10. MINING SOCIAL-NETWORK GRAPHS
In addition for the Laplacian matrix, the expression xT Lx has a useful equiv-
alent expression. Recall that L = D − A, where D and A are the degree and
adjacency matrices of the same graph. Thus, xT Lx = xT Dx − xT Ax. Let us
evaluate the term with D and then the term for A. Here, Dx is the column vec-
tor [d1 x1 , d2 x2 , .P
. . , dn xn ], where di is the degree of the ith node of the graph.
Thus, xT Dx is ni=1 di x2i .
Now, turn to xT Ax. The ith component of the column vector Ax is the sum
of xj over all j such that there is an edge (i, j) in the graph. Thus, −xT Ax is the
sum of −2xi xj over all pairs of nodes {i, j} such that there is an edge between
them. Note that the factor 2 appears because each set {i, j} corresponds to two
terms, −xi xj and −xj xi .
We can group the terms of xT Lx in a way that distributes the terms to each
pair {i, j}. From −xT Ax, we already have the term −2xi xj . From xT Dx, we
distribute the term di x2i to the di pairs that include node i. As a result, we
can associate with each pair {i, j} that has an edge between nodes i and j the
terms x2i − 2xi xj + x2j . This expression is equivalent to (xi − xj )2 . Therefore, we
have proved that xT Lx equals the sum over all graph edges (i, j) of (xi − xj )2 .
Recall that the second-smallest Pn eigenvalue is the minimum of this expression
under the constraint that i=1 x2i = 1. Intuitively, we minimize it by making
xi and xj close whenever there is an edge between √ nodes i and j in the graph.
We might imagine that we could choose xi = 1/ n for all i and thus make this
sum 0. However, recall that we are constrained to choose x to be orthogonal Pn to
1, which means the sum of the xi ’s is 0. We are also forced to make i=1 x2i be
1, so all components cannot be 0. As a consequence, x must have some positive
and some negative components.
We can obtain a partition of the graph by taking one set to be the nodes
i whose corresponding vector component xi is positive and the other set to
be those whose components are negative. This choice does not guarantee a
partition into sets of equal size, but the sizes are likely to be close. We believe
that the cut between the two sets will have a small number of edges because
(xi −xj )2 is likely to be smaller if both xi and xj have the same sign than if they
have different signs. Thus, minimizing xT Lx under the required constraints will
tend to give xi and xj the same sign if there is an edge (i, j).
Example 10.19 : Let us apply the above technique to the graph of Fig. 10.16.
The Laplacian matrix for this graph is shown in Fig. 10.17. By standard meth-
ods or math packages we can find all the eigenvalues and eigenvectors of this
matrix. We shall simply tabulate them in Fig. 10.18, from lowest eigenvalue to
highest. Note that we have not scaled the eigenvectors to have length 1, but
could do so easily if we wished.
10.4. PARTITIONING OF GRAPHS 379
1 4
2 5
3 6
The second eigenvector has three positive and three negative components.
It makes the unsurprising suggestion that one group should be {1, 2, 3}, the
nodes with positive components, and the other group should be {4, 5, 6}. ✷
Eigenvalue 0 1 3 3 4 5
Eigenvector 1 1 −5 −1 −1 −1
1 2 4 −2 1 0
1 1 1 3 −1 1
1 −1 −5 −1 1 1
1 −2 4 −2 −1 0
1 −1 1 3 1 −1
Figure 10.18: Eigenvalues and eigenvectors for the matrix of Fig. 10.17
component and only node 5 in the other. That partition would have a cut of size
two, as did the choice based on the threshold of zero, but the two components
have radically different sizes, so we would tend to prefer our original choice.
However, there are other cases where the threshold zero gives unequally sized
components, as would be the case if we used the third eigenvector in Fig. 10.18.
We may also want a partition into more than two components. One approach
is to use the method described above to split the graph into two, and then use
it repeatedly on the components to split them as far as desired. A second
approach is to use several of the eigenvectors, not just the second, to partition
the graph. If we use m eigenvectors, and set a threshold for each, we can get a
partition into 2m groups, each group consisting of the nodes that are above or
below threshold for each of the eigenvectors, in a particular pattern.
It is worth noting that each eigenvector except the first is the vector x that
minimizes xT Lx, subject to the constraint that it is orthogonal to all previous
eigenvectors. This constraint generalizes the constraints we described for the
second eigenvector in a natural way. As a result, while each eigenvector tries
to produce a minimum-sized cut, the fact that successive eigenvectors have to
satisfy more and more constraints generally causes the cuts they describe to be
progressively worse.
Example 10.20 : Let us reconsider the graph of Fig. 10.16, for which the
eigenvectors of its Laplacian matrix were tabulated in Fig. 10.18. The third
eigenvector, with a threshold of 0, puts nodes 1 and 4 in one group and the
other four nodes in the other. That is not a bad partition, but its cut size is
four, compared with the cut of size two that we get from the second eigenvector.
If we use both the second and third eigenvectors, we put nodes 2 and 3 in
one group, because their components are positive in both eigenvectors. Nodes
5 and 6 are in another group, because their components are negative in the
second eigenvector and positive in the third. Node 1 is in a group by itself
because it is positive in the second eigenvector and negative in the third, while
node 4 is also in a group by itself because its component is negative in both
eigenvectors. This partition of a six-node graph into four groups is too fine a
partition to be meaningful. But at least the groups of size two each have an
edge between the nodes, so it is as good as we could ever get for a partition
into groups of these sizes. ✷