Search

Search papers and lessons

Clustering Coefficient

Level 2 · 10 min read

The clustering coefficient of a vertex is the fraction of pairs of its neighbours that are themselves joined, a number from 0 to 1 that measures how much a vertex's friends know each other.

On this page

  • Colour = topic mix
  • Discrete math
  • ReadReady to readNot yet

TL;DR

The clustering coefficient of a vertex asks a simple question: of all the pairs of neighbours that a vertex has, how many of those pairs are joined to each other? The answer is a fraction between 0 and 1. A vertex whose friends all know one another scores 1, and a vertex whose friends never know one another scores 0. It matters because many real networks have much more of this closed, triangle-rich structure than random networks of the same size.

Builds on: Graph, Vertex Degree · Leads to: the small-world model, Degree Distribution

Where it's used

Friend groups. Take one person in a social network. Their friends often know each other: a family, a team, or a class forms a tight cluster. The clustering coefficient measures how strongly a person's network of friends is closed in this way, and it is a standard number in studies of friendship networks.

Protein interaction maps. In biology, a network (a Graph) has proteins as its vertices, and a line joins two proteins that bind each other. Proteins that work together in one machine tend to bind each other in small groups. High clustering around a protein is a hint that it sits inside such a group, and researchers use this hint to suggest which proteins might share a job.

Small-world networks. Duncan Watts and Steven Strogatz noticed in 1998 that many real networks, such as the social network of film actors and the power grid of the western United States, combine high clustering with short paths between any two vertices. A purely random graph of the same size has short paths but very little clustering. The clustering coefficient is the number that separates the two cases, and it is the reason the small-world model was built.

How it works

Take a small friendship network with five people: Ana, Ben, Cara, Dev and Eli. Ana is friends with Ben, Cara and Dev. Ben and Cara are friends, Cara and Dev are friends, and Eli is friends only with Dev. We want Ana's clustering coefficient.

  1. Find the neighbours. Ana's neighbours are Ben, Cara and Dev. Her degree is 3. Check: three friends, so the degree is 3.

  2. List every pair of neighbours. There are three pairs: Ben and Cara, Ben and Dev, Cara and Dev. Check: three people give 3 pairs, because you pick 2 of them and the order does not matter.

  3. Count the pairs that are joined. Ben and Cara are friends, so that pair counts. Ben and Dev are not friends, so that pair does not count. Cara and Dev are friends, so that pair counts. The count is 2. Check: you looked at each of the three pairs exactly once.

  4. Divide by the number of possible pairs. The count is 2 out of 3 possible pairs, so the clustering coefficient is 2/32/3. Check: 2/32/3 is between 0 and 1, as every clustering coefficient must be.

  5. Read the result. Ana's friends know each other about two times in three. That is high clustering for a friend group of this size.

flowchart LR
  A[Pick a vertex] --> B[List its neighbours]
  B --> C[Count joined pairs of neighbours]
  C --> D[Divide by all possible pairs]
  D --> E[Clustering coefficient in 0 to 1]

The math

Definition

Definition: Local clustering coefficient

Let G=(V,E)G = (V, E) be a simple Graph. For a vertex vv with degree kv≥2k_v \geq 2, let N(v)N(v) be its set of neighbours. Let LvL_v be the number of edges that have both ends in N(v)N(v). The local clustering coefficient of vv is

Cv=Lv(kv2)=2Lvkv(kv−1).C_v = \frac{L_v}{\binom{k_v}{2}} = \frac{2 L_v}{k_v (k_v - 1)}.

Here (kv2)=kv(kv−1)/2\binom{k_v}{2} = k_v(k_v - 1)/2 is the number of ways to choose two of the kvk_v neighbours (the standard counting rule for choosing a pair), which is the number of possible pairs.

Read the formula as follows: LvL_v is the count of joined pairs among the neighbours, and the denominator is the count of all pairs. The fraction is the share of possible pairs that are joined. This is steps 3 and 4 of the walkthrough written in symbols.

Steps 2 to 4 in symbols

For Ana, k=3k = 3, so the number of possible pairs is 3⋅2/2=33 \cdot 2 / 2 = 3. This matches the three pairs we listed. The joined pairs are Ben–Cara and Cara–Dev, so L=2L = 2.

CAna=2⋅23⋅2=46=23.C_{\text{Ana}} = \frac{2 \cdot 2}{3 \cdot 2} = \frac{4}{6} = \frac{2}{3}.

Beyond one vertex (not a walkthrough step)

One vertex tells you about its neighbourhood. To describe the whole graph, take the average of the local values over all nn vertices. Vertices of degree 0 or 1 have no pairs of neighbours, so their value is not defined. The usual convention sets it to 0, and some texts leave those vertices out of the average. The average clustering coefficient is

Cˉ=1n∑v∈VCv,\bar{C} = \frac{1}{n} \sum_{v \in V} C_v,

where the sum is the sum of the local values, and nn is the number of vertices. This is the average of the list of local values.

Worked examples

Example
1. A path of three vertices (tiny)

Take three vertices in a line: AA joined to BB, and BB joined to CC.

  1. Vertex BB has neighbours AA and CC, so kB=2k_B = 2.
  2. The number of possible pairs is (22)=1\binom{2}{2} = 1: the single pair AA, CC.
  3. Is AA joined to CC? No. So LB=0L_B = 0.
  4. The clustering coefficient is CB=0/1=0C_B = 0 / 1 = 0.
  5. Interpretation: BB links two people who do not know each other, so its neighbourhood has no closure at all.
Example
2. A square with one diagonal (standard)

Take four vertices AA, BB, CC, DD with edges ABAB, BCBC, CDCD, DADA and the diagonal ACAC. The sets of neighbours are N(A)={B,C,D}N(A) = \{B, C, D\}, N(B)={A,C}N(B) = \{A, C\}, N(C)={A,B,D}N(C) = \{A, B, D\} and N(D)={A,C}N(D) = \{A, C\}.

  1. Vertex AA has k=3k = 3, so there are 33 pairs: BCBC, BDBD, CDCD.
  2. Joined pairs among them: BCBC yes, CDCD yes, BDBD no. So LA=2L_A = 2 and CA=2/3C_A = 2/3.
  3. Vertex BB has k=2k = 2, so there is one pair, ACAC. It is joined, so LB=1L_B = 1 and CB=1/1=1C_B = 1/1 = 1.
  4. Vertex CC has k=3k = 3, so the pairs are ABAB, ADAD, BDBD. Joined: ABAB yes, ADAD yes, BDBD no. So CC=2/3C_C = 2/3.
  5. Vertex DD has k=2k = 2, with the pair ACAC, which is joined. So CD=1C_D = 1.
  6. Average: (2/3+1+2/3+1)/4=(10/3)/4=5/6(2/3 + 1 + 2/3 + 1)/4 = (10/3)/4 = 5/6, about 0.830.83.
  7. Interpretation: the two vertices with degree 2 are fully closed, and the two with degree 3 are closed most of the time.
Example
3. Friends of one person (realistic)

Ana has four friends: Ben, Cara, Dev and Eli. Among these four, the friendships are Ben–Cara, Cara–Dev and Dev–Eli.

  1. Ana's degree is k=4k = 4.
  2. The number of possible pairs among four friends is 4⋅3/2=64 \cdot 3 / 2 = 6.
  3. Joined pairs: Ben–Cara yes, Cara–Dev yes, Dev–Eli yes. The other three pairs (Ben–Dev, Ben–Eli, Cara–Eli) are not joined. So L=3L = 3.
  4. The clustering coefficient is C=3/6=1/2C = 3 / 6 = 1/2.
  5. Interpretation: half of the possible friendships among Ana's friends exist. Her circle is partly closed, with two small chains of friends rather than one tight group.

Try it: a person has 5 contacts, and 4 of the 10 possible pairs of those contacts know each other. What is the person's clustering coefficient?

Answer: C=4/10=0.4C = 4/10 = 0.4. The number of possible pairs is 5⋅4/2=105 \cdot 4 / 2 = 10, and the fraction of joined pairs is 4/104/10.

Common mistakes and tradeoffs

Mistake 1: counting edges instead of pairs. It is tempting to divide the number of edges around a vertex by its degree. In fact the denominator is the number of pairs of neighbours, k(k−1)/2k(k-1)/2, not kk. Ana has 3 edges to friends and 3 pairs of friends, but the pairs are what the clustering coefficient counts. With k=4k = 4 and 3 joined pairs, dividing by 4 would give 3/43/4, which is wrong; the correct value is 1/21/2.

Mistake 2: confusing the local and the global measure. It is tempting to think that the average of the local values is the same as the overall fraction of closed structures. In fact they differ. The global version, usually called transitivity, is 3T/W3T / W, where TT is the number of triangles and WW is the number of connected triples, meaning sets of two edges that share a middle vertex. For the square with a diagonal in Example 2, T=2T = 2 (the triangles ABCABC and ACDACD) and W=3+1+3+1=8W = 3 + 1 + 3 + 1 = 8, so transitivity is 6/8=3/46/8 = 3/4. The average local value is 5/65/6. Both are valid, but they answer different questions, and the global one weights high-degree vertices more heavily.

Mistake 3: treating degree 0 and 1 as zero, as if it were a fact. A vertex with one friend has no pairs of friends, so its clustering coefficient is not defined. Setting it to 0 is a convention that changes the average. Always say which convention you used.

When to use it: it is the standard way to ask whether a network has tight local groups. It is cheap to compute: one pass over each neighbourhood.

When not to use it: it says nothing about how far apart two distant vertices are. A network can have high clustering and still have long paths. For that, look at path lengths, and compare the clustering with a random model such as the Erdős–Rényi random graph of the same size and density. For the overall spread of degrees, see the Degree Distribution. To check whether two vertices are joined, the Adjacency Matrix is faster than scanning neighbour lists.

History

Sociologists studied the tendency for "a friend of a friend is also a friend" for a long time, often under the name transitivity, long before the measure had a standard form. Network physicists brought the local clustering coefficient into common use. In 1998 Watts and Strogatz showed that a small amount of random rewiring in a regular ring of vertices gave a network with high clustering and short paths at the same time, which is the combination found in many real networks. Their work made the clustering coefficient a standard reference number for comparing real networks with random ones. The Wikipedia article on the clustering coefficient gives the standard definitions and their variants.

Recap

  • A vertex's clustering coefficient is the fraction of pairs of its neighbours that are joined to each other.
  • Its formula is Cv=2Lv/(kv(kv−1))C_v = 2L_v / (k_v(k_v-1)), where LvL_v counts the joined pairs among the kvk_v neighbours.
  • The average over all vertices summarises a whole graph, and degree 0 or 1 needs a stated convention.
  • Clustering is compared with path lengths and random models, which is the basis of the small-world model.

What to read next: the small-world model uses this measure to build networks that are both clustered and short-path. The Degree Distribution describes the other basic statistic of a network.

Check yourself

QuestionA vertex has 4 neighbours. How many pairs of neighbours are there?Show answer

Choose 2 of the 4 neighbours: (42)=4⋅3/2=6\binom{4}{2} = 4 \cdot 3 / 2 = 6 pairs.

QuestionA vertex has degree 5, and 6 of the possible pairs of its neighbours are joined. What is its clustering coefficient?Show answer

The number of possible pairs is 5⋅4/2=105 \cdot 4 / 2 = 10. The clustering coefficient is 6/10=0.66/10 = 0.6.

QuestionWhy is the clustering coefficient always between 0 and 1?Show answer

It is a count of joined pairs, LvL_v, divided by the count of all possible pairs, (kv2)\binom{k_v}{2}. The joined pairs are a subset of the possible pairs, so the count on top can be no larger than the count on the bottom. The smallest it can be is 0, when no pair is joined, and the largest is 1, when every pair is joined.

QuestionTwo vertices both have degree 4. One has clustering 1 and the other has clustering 0. What does this say about their friends?Show answer

The vertex with clustering 1 has friends who all know each other, so its neighbourhood is one tight group. The vertex with clustering 0 has friends who never know each other, so each friend connects it to a different part of the network. Both have the same number of friends, but the structure around them is completely different.

QuestionA network has 5 vertices with clustering values 1, 0, 0.5, 0.5 and 0 (the last one is a degree-1 vertex, set to 0 by convention). What is the average clustering coefficient?Show answer

The sum is 1+0+0.5+0.5+0=21 + 0 + 0.5 + 0.5 + 0 = 2. Dividing by n=5n = 5 gives 2/5=0.42/5 = 0.4.

Sources