심층 분석 - Twitter 네트워크 II
이제 매개 중심성에 대해서도 같은 방식으로 심층 분석을 해 보겠습니다! 몇 가지 힌트를 드리면, 매개 중심성은 nx.betweenness_centrality(G)로 계산한다는 점을 기억하세요.
이 연습은 강의의 일부입니다
Python으로 시작하는 네트워크 분석
연습 안내
- 가장 높은 매개 중심성을 가진 노드(들)를 반환하는 함수
find_node_with_highest_bet_cent(G)를 작성하세요.G의 매개 중심성을 계산하세요.list(bet_cent.values())에max()함수를 적용해 최대 매개 중심성을 구하세요.- 매개 중심성 딕셔너리
bet_cent.items()를 순회하세요. - 현재 노드
k의 매개 중심성 값v가max_bc와 같다면, 해당 노드를 노드 집합에 추가하세요.
- 작성한 함수를 사용해
T에서 매개 중심성이 가장 높은 노드(들)를 찾으세요. - 올바른 노드를 찾았는지 확인하는 단언문을 작성하세요. 이는 이미 준비되어 있으니, 'Submit Answer'를 눌러 결과를 확인하세요!
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Define find_node_with_highest_bet_cent()
def find_node_with_highest_bet_cent(G):
# Compute betweenness centrality: bet_cent
bet_cent = ____
# Compute maximum betweenness centrality: max_bc
max_bc = ____
nodes = set()
# Iterate over the betweenness centrality dictionary
for k, v in ____:
# Check if the current value has the maximum betweenness centrality
if ____ == ____:
# Add the current node to the set of nodes
____
return nodes
# Use that function to find the node(s) that has the highest betweenness centrality in the network: top_bc
top_bc = ____
print(top_bc)
# Write an assertion statement that checks that the node(s) is/are correctly identified.
for node in top_bc:
assert nx.betweenness_centrality(T)[node] == max(nx.betweenness_centrality(T).values())