DEPARTMENT OF ARTIFICIAL INTELLIGENCE
&
DATA SCIENCE
Subject: Social Media Analytics Course Code: CSDOL8023
Semester: 8 Course: AI&DS
Laboratory no.: 302 Name of subject teacher: Prof. Gitanjali Korgaonkar
Name of student: Janavi Kachi Roll no: VU2S2223008
Experiment No. 6
Aim: Develop Structure based social media analytics model for any business. (e.g. Structure Based Models -
community detection, influence analysis)
Theory:
Centrality is a key concept in graph theory that refers to measures of the relative importance or "centrality" of a
node in a graph. Nodes that are more "central" in a network are typically more influential or have more
connections to other important nodes.
Types of Centrality:
1. Degree Centrality: Measures the number of direct connections a node has. Nodes with high degree
centrality are well-connected.
2. Betweenness Centrality: Measures how often a node lies on the shortest path between other nodes,
indicating its role as a bridge in the network.
3. Closeness Centrality: Measures how quickly a node can access all other nodes in the network,
indicating its ability to reach others with fewer steps.
4. Eigenvector Centrality: Measures the influence of a node based on the number and quality
(importance) of its neighbors.
The NetworkX library in Python is designed for the creation, manipulation, and study of the structure,
dynamics, and functions of complex networks. It provides tools for the analysis of graphs and networks, which
can represent a wide range of real-world systems, from social networks to transportation systems, biological
networks, and more.
● Graph: A graph is a collection of nodes (also called vertices) connected by edges (also called links).
● Directed vs. Undirected Graphs:
o Undirected Graph: The edges have no direction. That is, the relationship between nodes is
bidirectional.
o Directed Graph (DiGraph): The edges have direction, indicating a one-way relationship
between nodes.
import networkx as nx
import matplotlib.pyplot as plt
# Define nodes
nodes = ['x', 'a', 'b', 'c', 'd', 'e']
# Create graph
G = nx.Graph()
G.add_nodes_from(nodes)
# Add edges to connect 'x' to all other nodes
for node in nodes:
if node != 'x':
G.add_edge('x', node)
# Add edges between other nodes (example)
G.add_edge('a', 'b')
G.add_edge('b', 'c')
G.add_edge('c', 'd')
G.add_edge('d', 'e')
G.add_edge('e', 'a') # Create a cycle
# Draw the graph with 'x' in the center
pos = nx.spring_layout(G, seed=42) # Use spring layout for better visualization
pos['x'] = (0, 0) # Place 'x' at the center
nx.draw(G, pos, with_labels=True, node_size=500, font_size=10)
plt.show()
Conclusion: Thus, we developed Structure based social media analytics model for business.
R1 R2 R3
DOP DOS Conduction File Record Viva -Voce Total Signature
5 Marks 5 Marks 5 Marks 15 Marks