시작하기무료로 시작하기

프로젝션에서 연결 중심성 그리기

여기서는 원본 그래프 G, 사람 그래프 프로젝션 peopleG, 클럽 그래프 프로젝션 clubsG에 대해 각 연결 중심성 분포를 비교해 보겠습니다. 이를 통해 이분 그래프와 단일 그래프에서의 연결 중심성 지표 계산 방식 차이를 다시 한 번 확인할 수 있습니다. 노드 목록 peopleclubs는 미리 로드되어 있습니다.

영상에서 보았듯이, 이분 그래프용 함수는 노드 컨테이너 하나를 인자로 받지만, 모든 노드의 연결 중심성 점수를 반환합니다. 또한 연결 중심성 점수는 사전(노드에서 점수로의 매핑) 형태로 저장된다는 점을 기억하세요.

이 연습은 강의의 일부입니다

Python 중급 네트워크 분석

강의 보기

연습 안내

  • 이분 그래프 모듈의 degree_centrality 함수(nx.bipartite.degree_centrality())를 사용해 원본 그래프 G의 연결 중심성 분포를 그리세요. 이 함수는 두 개의 인자를 받습니다: 그래프 G와 노드 목록 중 하나(people 또는 clubs).
  • NetworkX의 일반(비-이분) degree_centrality 함수(nx.degree_centrality())를 사용해 peopleG 그래프의 연결 중심성 분포를 그리세요.
  • NetworkX의 일반(비-이분) degree_centrality 함수(nx.degree_centrality())를 사용해 clubsG 그래프의 연결 중심성 분포를 그리세요.

실습형 인터랙티브 연습

이 예제를 이 샘플 코드를 완성하여 풀어보세요.

import matplotlib.pyplot as plt 

# Plot the degree centrality distribution of both node partitions from the original graph
plt.figure()
original_dc = ____
# Remember that you can directly plot dictionary values.
plt.hist(____, alpha=0.5)
plt.yscale('log')
plt.title('Bipartite degree centrality')
plt.show()


# Plot the degree centrality distribution of the peopleG graph
plt.figure()  
people_dc = ____
plt.hist(____)
plt.yscale('log')
plt.title('Degree centrality of people partition')
plt.show()

# Plot the degree centrality distribution of the clubsG graph
plt.figure() 
clubs_dc = ____
plt.hist(____)
plt.yscale('log')
plt.title('Degree centrality of clubs partition')
plt.show()
코드 편집 및 실행