시작하기무료로 시작하기

심화 학습 - Twitter 네트워크

이번에는 Twitter 네트워크를 깊이 있게 살펴보며 앞에서 배운 내용을 복습하겠습니다. 먼저, 한 단계 떨어진 많은 사람에게 메시지를 매우 효율적으로 전파할 수 있는 노드를 찾아보겠습니다.

NetworkX는 nx로 미리 임포트되어 있습니다.

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

Python으로 시작하는 네트워크 분석

강의 보기

연습 안내

  • 다음 단계를 따라, 가장 높은 차수 중심성을 갖는 노드(들)를 반환하는 함수 find_nodes_with_highest_deg_cent(G)를 작성하세요.
    • G의 차수 중심성을 계산합니다.
    • list(deg_cent.values())max() 함수를 적용해 최대 차수 중심성을 계산합니다.
    • 차수 중심성 딕셔너리 deg_cent.items()를 순회합니다.
    • 현재 노드 k의 차수 중심성 값 vmax_dc와 같다면, 노드 집합에 추가합니다.
  • 작성한 함수를 사용해 T에서 가장 높은 차수 중심성을 갖는 노드(들)를 찾으세요.
  • 노드(들)가 올바르게 식별되었는지 확인하는 assert 문을 작성하세요. 이 부분은 이미 준비되어 있으니, 'Submit Answer'를 눌러 결과를 확인하세요!

실습형 인터랙티브 연습

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

# Define find_nodes_with_highest_deg_cent()
def find_nodes_with_highest_deg_cent(G):

    # Compute the degree centrality of G: deg_cent
    deg_cent = ____

    # Compute the maximum degree centrality: max_dc
    max_dc = ____

    nodes = set()

    # Iterate over the degree centrality dictionary
    for k, v in ____:

        # Check if the current value has the maximum degree centrality
        if ____ == ____:

            # Add the current node to the set of nodes
            ____

    return nodes

# Find the node(s) that has the highest degree centrality in T: top_dc
top_dc = ____
print(top_dc)

# Write the assertion statement
for node in top_dc:
    assert nx.degree_centrality(T)[node] == max(nx.degree_centrality(T).values())
코드 편집 및 실행