---
id: wiki-2026-0508-social-network-analysis
title: Social Network Analysis
category: 10_Wiki/Topics
status: verified
canonical_id: self
aliases: [SNA, Network-Analysis-Social]
duplicate_of: none
source_trust_level: A
confidence_score: 0.9
verification_status: applied
tags: [graph, network, sna, sociology, analysis]
raw_sources: []
last_reinforced: 2026-05-10
github_commit: pending
tech_stack:
  language: python
  framework: networkx-graph-tool
---

# Social Network Analysis

## 매 한 줄
> **"매 사람 사이 의 관계 = 매 graph"**. SNA 의 actor 를 node, relation 을 edge 로 modeling — 매 1930s sociometry (Moreno) 에서 출발, 2026 에 GNN, link prediction, community detection 의 backbone 으로 산업 (Meta, LinkedIn, Twitter/X) 에 적용.

## 매 핵심

### 매 unit
- **Node (vertex)**: actor — person, org, account.
- **Edge (tie)**: relation — friendship, follow, co-authorship, message.
- **Directed vs undirected**: follow (directed) vs friendship (undirected).
- **Weighted**: tie strength — message count, interaction frequency.

### 매 metric
- **Degree centrality**: 매 node 의 edge count → "popularity".
- **Betweenness**: shortest-path 매 통과 비율 → "broker".
- **Closeness**: 매 다른 node 까지 평균 거리 → "reach".
- **Eigenvector / PageRank**: 매 중요 node 와 의 connection → recursive importance.
- **Clustering coefficient**: 매 ego network 의 triangle 비율 → cohesion.

### 매 응용
1. Community detection (Louvain, Leiden) — friend group, fraud ring.
2. Link prediction — friend-of-friend recommendation.
3. Influence maximization — viral marketing seed selection.
4. Anomaly detection — bot, sybil, money laundering ring.

## 💻 패턴

### 1. NetworkX basic centrality
```python
import networkx as nx
G = nx.read_edgelist("twitter_follows.txt", create_using=nx.DiGraph)
deg = nx.degree_centrality(G)
btw = nx.betweenness_centrality(G, k=500)  # k=sample for large graphs
top = sorted(deg.items(), key=lambda x: -x[1])[:10]
```

### 2. Louvain community detection
```python
import networkx as nx
import community as community_louvain  # python-louvain
partition = community_louvain.best_partition(G.to_undirected(), resolution=1.0)
# {node: community_id}
mod = community_louvain.modularity(partition, G.to_undirected())
```

### 3. PageRank for influence
```python
pr = nx.pagerank(G, alpha=0.85, max_iter=100)
influencers = sorted(pr.items(), key=lambda x: -x[1])[:20]
```

### 4. Link prediction (Adamic-Adar)
```python
# Predict missing edges via shared neighbors weighted by inverse log-degree
preds = nx.adamic_adar_index(G.to_undirected(), [(u, v) for u in nodes for v in nodes if u != v])
ranked = sorted(preds, key=lambda x: -x[2])[:100]
```

### 5. Graph-tool fast Louvain (large scale)
```python
import graph_tool.all as gt
g = gt.load_graph("network.gt")
state = gt.minimize_blockmodel_dl(g)  # SBM, faster than networkx for >1M nodes
state.draw(output="communities.pdf")
```

### 6. GNN node embedding (PyTorch Geometric, 2026)
```python
from torch_geometric.nn import GraphSAGE
model = GraphSAGE(in_channels=64, hidden_channels=128, num_layers=2, out_channels=32)
emb = model(data.x, data.edge_index)
# 매 emb → downstream classifier / link prediction
```

### 7. Ego network extraction
```python
ego = nx.ego_graph(G, node="alice", radius=2)
# 매 alice 의 2-hop neighborhood
```

### 8. Anomaly via local clustering
```python
cc = nx.clustering(G)
# 매 high degree + low clustering → 매 bot/spam 의 의심
suspects = [n for n, c in cc.items() if c < 0.01 and G.degree(n) > 100]
```

## 매 결정 기준
| 상황 | Approach |
|---|---|
| <100K nodes, prototyping | NetworkX |
| 1M~100M nodes | graph-tool, igraph (C-backed) |
| Community detection 정확도 | Leiden > Louvain |
| Predictive (link, label) | GNN (GraphSAGE, GAT) |
| Real-time recommendation | Embedding + ANN (FAISS) |
| Visualization | Gephi, Cytoscape |

**기본값**: NetworkX 로 prototype → Leiden community + PageRank → scale 시 graph-tool / GNN.

## 🔗 Graph
- 부모: [[Graph Theory]] · [[Statistics]]
- 변형: [[Knowledge Graph]] · [[Knowledge-Graph-Foundations]]
- 응용: [[Information Retrieval (IR)]] · [[Ranking-Algorithms]]
- Adjacent: [[PageRank]] · [[Eigenvalues-and-Eigenvectors]]

## 🤖 LLM 활용
**언제**: community summarization, node description generation, anomaly explanation, relation extraction from text → graph.
**언제 X**: 매 raw centrality computation — LLM 의 X, 매 algorithmic library 의 사용.

## ❌ 안티패턴
- **Treat directed as undirected without thinking**: 매 follow 의 reciprocal X — directionality 의 의미 의 손실.
- **Ignore graph size in metric choice**: betweenness 의 O(VE) — 매 1M node 의 X, sampling (k 파라미터) 의 사용.
- **Static analysis on temporal data**: 매 friendship 의 evolve — 매 snapshot vs temporal graph 의 구분.
- **Modularity maximization without resolution check**: 매 resolution limit — small communities 의 merge 의 위험.

## 🧪 검증 / 중복
- Verified (Wasserman & Faust *Social Network Analysis*, NetworkX docs, *Networks* by Newman).
- 신뢰도 A.

## 🕓 Changelog
| 날짜 | 변경 |
|---|---|
| 2026-05-08 | Phase 1 |
| 2026-05-10 | Manual cleanup — SNA fundamentals, NetworkX/graph-tool/GNN patterns. |
