0% found this document useful (0 votes)
23 views6 pages

SNA (Exp-3) B1

The document outlines an experiment focused on calculating and visualizing various network centrality measures using NetworkX, including degree, betweenness, closeness, eigenvector, PageRank, and Katz centrality. Each measure provides distinct insights into node importance and connectivity within a network, highlighting different aspects such as direct connections, influence, and information flow. The experiment concludes that these centrality measures collectively enhance understanding of the network's structure and dynamics.

Uploaded by

Raj Shah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views6 pages

SNA (Exp-3) B1

The document outlines an experiment focused on calculating and visualizing various network centrality measures using NetworkX, including degree, betweenness, closeness, eigenvector, PageRank, and Katz centrality. Each measure provides distinct insights into node importance and connectivity within a network, highlighting different aspects such as direct connections, influence, and information flow. The experiment concludes that these centrality measures collectively enhance understanding of the network's structure and dynamics.

Uploaded by

Raj Shah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Name: Het Shirsekar SAP ID: 60019210082

Branch: CSE(ICB) Batch: B2 Roll No: T043

SNA Experiment – 3
Aim:
To build network measures using NetworkX Node centrality measures.

Theory:
1. Degree Centrality:
 Definition: Degree centrality assigns an importance score based simply on the number
of links held by each node.
 What it tells us: How many direct, ‘one hop’ connections each node has to other nodes
in the network.
 When to use it: For finding very connected individuals, popular individuals, individuals
who are likely to hold most information or individuals who can quickly connect with
the wider network.
 A bit more detail: Degree centrality is the simplest measure of node connectivity.
Sometimes it’s useful to look at in-degree (number of inbound links) and out-degree
(number of outbound links) as distinct measures, for example when looking at
transactional data or account activity.
2. Betweenness Centrality:
 Definition: Betweenness centrality measures the number of times a node lies on the
shortest path between other nodes.
 What it tells us: This measure shows which nodes are ‘bridges’ between nodes in a
network. It does this by identifying all the shortest paths and then counting how many
times each node falls on one.
 When to use it: For finding the individuals who influence the flow around a system.
 A bit more detail: Betweenness is useful for analyzing communication dynamics, but
should be used with care. A high betweenness count could indicate someone holds
authority over disparate clusters in a network, or just that they are on the periphery of
both clusters.
3. Closeness Centrality:
 Definition: Closeness centrality scores each node based on their ‘closeness’ to all other
nodes in the network.
 What it tells us: This measure calculates the shortest paths between all nodes, then
assigns each node a score based on its sum of shortest paths.
 When to use it: For finding the individuals who are best placed to influence the entire
network most quickly.
 A bit more detail: Closeness centrality can help find good ‘broadcasters’, but in a
highly-connected network, you will often find all nodes have a similar score. What may
be more useful is using Closeness to find influencers in a single cluster.
4. Eigenvector Centrality:
 Definition: Like degree centrality, EigenCentrality measures a node’s influence based
on the number of links it has to other nodes in the network. EigenCentrality then goes
a step further by also taking into account how well connected a node is, and how many
links their connections have, and so on through the network.
 What it tells us: By calculating the extended connections of a node, EigenCentrality can
identify nodes with influence over the whole network, not just those directly connected
to it.
 When to use it: EigenCentrality is a good ‘all-round’ SNA score, handy for
understanding human social networks, but also for understanding networks like
malware propagation.
 A bit more detail: Our tools calculate each node’s EigenCentrality by converging on an
eigenvector using the power iteration method.
5. PageRank Centrality:
 Definition: PageRank is a variant of EigenCentrality, also assigning nodes a score based
on their connections, and their connections’ connections. The difference is that
PageRank also takes link direction and weight into account – so links can only pass
influence in one direction, and pass different amounts of influence.
 What it tells us: This measure uncovers nodes whose influence extends beyond their
direct connections into the wider network.
 When to use it: Because it takes into account direction and connection weight,
PageRank can be helpful for understanding citations and authority.
 A bit more detail: PageRank is famously one of the ranking algorithms behind the
original Google search engine (the ‘Page’ part of its name comes from creator and
Google founder, Larry Page).
6. Katz Centrality:
 Katz centrality is a measure of a node’s influence that extends degree centrality by also
considering the influence of neighbors. It assigns a score based on both direct and
indirect connections, but it decays the influence of more distant nodes by a factor 𝛼.
 Katz centrality considers both direct and indirect neighbors.
 Unlike degree centrality, it also accounts for nodes that are further away but still exert
influence over a node.
Code:
import networkx as nx
import matplotlib.pyplot as plt

G = nx.read_edgelist('email.txt', nodetype=int)

degree_centrality = nx.degree_centrality(G)

betweenness_centrality = nx.betweenness_centrality(G)

closeness_centrality = nx.closeness_centrality(G)

eigenvector_centrality = nx.eigenvector_centrality(G)

katz_centrality = nx.katz_centrality(G, alpha=0.1, beta=1.0)

# Function to print centrality scores for each node


def print_centrality_scores(centrality, centrality_name):
print(f"\n{centrality_name} Scores:")
for node, score in centrality.items():
print(f"Node {node}: {score}")

# Print centrality scores


print_centrality_scores(degree_centrality, "Degree Centrality")
print_centrality_scores(betweenness_centrality, "Betweenness
Centrality")
print_centrality_scores(closeness_centrality, "Closeness Centrality")
print_centrality_scores(eigenvector_centrality, "Eigenvector
Centrality")
print_centrality_scores(katz_centrality, "Katz Centrality")

# Define a function to draw and display graph based on centrality


scores
def visualize_centrality(centrality, centrality_name):
node_color = [centrality[node] for node in G.nodes()]
plt.figure(figsize=(8, 6))
nx.draw(G, with_labels=True, node_size=700, node_color=node_color,
cmap=plt.cm.viridis, font_size=12)
plt.title(f"Graph Visualization with {centrality_name}")
plt.show()

# Visualize centrality measures


visualize_centrality(degree_centrality, "Degree Centrality")
visualize_centrality(betweenness_centrality, "Betweenness Centrality")
visualize_centrality(closeness_centrality, "Closeness Centrality")
visualize_centrality(eigenvector_centrality, "Eigenvector Centrality")
visualize_centrality(katz_centrality, "Katz Centrality")
Output:
Conclusion:
In this experiment, we computed and visualized multiple centrality measures to
assess node importance in a network. Degree centrality highlighted well-
connected nodes, while betweenness centrality identified critical bridges for
information flow. Closeness centrality emphasized nodes that can quickly reach
others, and eigenvector centrality revealed influential nodes connected to other
central nodes. Katz centrality combined both direct and indirect influence,
offering a more comprehensive measure of node importance. Each centrality
measure provided unique insights into the network's structure and dynamics.

You might also like