시작하기무료로 시작하기

학생 프로젝션의 차수 중심성 분포 시각화

이번 연습에서는 학생 프로젝션의 차수 중심성 분포를 시각화해 보겠습니다. 이전에 학습한 두 가지 개념(차수 중심성과 프로젝션)을 복습하는 과제입니다.

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

Python 중급 네트워크 분석

강의 보기

연습 안내

  • 'student' 파티션의 노드를 student_nodes라는 리스트로 가져오세요.
    • 리스트 컴프리헨션을 사용해 G의 모든 노드(메타데이터 포함)를 순회하며, d'bipartite' 키워드가 'student'와 같은지 확인하세요.
  • 학생 노드 프로젝션을 G_students라는 그래프로 생성하세요. 이를 위해 nx.bipartite.projected_graph() 함수를 사용하고, 키워드 인수 nodes=student_nodes를 지정하세요.
  • nx.degree_centrality()G_students의 차수 중심성을 계산하고 결과를 dcs로 저장하세요.
  • 차수 중심성 값의 히스토그램을 그리세요.

실습형 인터랙티브 연습

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

# Import necessary modules
import matplotlib.pyplot as plt
import networkx as nx

# Get the student partition's nodes: student_nodes
student_nodes = [n for n, d in ____ if d['____'] == '____']

# Create the students nodes projection as a graph: G_students
G_students = ____

# Calculate the degree centrality using nx.degree_centrality: dcs
dcs = ____

# Plot the histogram of degree centrality values
plt.hist(list(____))
plt.yscale('log')  
plt.show() 
코드 편집 및 실행