in

# Closeness and Communities: Analyzing Social Networks with Python and NetworkX — Half 3 | by Christine Egan | Jun, 2023

## Study communities and closeness centrality in social community evaluation with Python and NetworkX

In Part 2, we expanded our understanding of social community evaluation by graphing the relationships between the members of the bands Smashing Pumpkins and Zwan. Then, we examined metrics like diploma centrality and betweenness centrality to research the relationships between the members of the completely different bands. On the identical time, we mentioned how area information helps to tell our understanding of the outcomes.

In Half 3, we are going to cowl the fundamentals of closeness centrality and the way it’s calculated. Then, we are going to reveal easy methods to calculate closeness centrality with NetworkX utilizing Billy Corgan’s community for instance.

Earlier than you begin…

1. Do you could have primary information of Python? If not, start here.
2. Are you aware of primary ideas in social community evaluation, like nodes and edges? If not, start here.
3. Are you snug with diploma centrality and betweenness centrality? If not, start here.

## Closeness Centrality

Closeness centrality is a measure in social community evaluation that quantifies how shut a node is to all different nodes in a community by way of the shortest path distance.

Closeness centrality focuses on the effectivity of knowledge or useful resource movement inside a community. The concept is that nodes with larger closeness centrality are capable of attain different nodes extra shortly and effectively, as they’ve shorter common distances to the remainder of the community.

The closeness centrality of a node is calculated because the reciprocal of the sum of the shortest path distances (SPD) from that node to all different nodes within the community.

Closeness Centrality = 1 / (Sum of SPD from the node to all different nodes)

Greater values point out better centrality and effectivity in info movement throughout the community.

## Calculating Closeness Centrality

Let’s break it down, utilizing a easy community with eight nodes.

1. Calculate the shortest path distances (SPD) from node A to all different nodes. For our instance, we are going to use easy instance distances. In follow, this could be performed with a shortest path algorithm like Breadth-First Search or Dijkstra’s algorithm.