Aan de slagGa gratis aan de slag

Visualize the degree centrality distribution of the students projection

In this exercise, you will visualize the degree centrality distribution of the students projection. This is a recap of two previous concepts you've learned: degree centralities, and projections.

Deze oefening maakt deel uit van de cursus

Intermediate Network Analysis in Python

Cursus bekijken

Oefeninstructies

  • Get the nodes of the 'student' partition into a list called student_nodes.
    • Use a list comprehension to do this, iterating over all the nodes of G (including the metadata), and checking to see if the 'bipartite' keyword of d equals 'student'.
  • Create the students nodes projection as a graph called G_students. Use the nx.bipartite.projected_graph() function to do this. Be sure to specify the keyword argument nodes=student_nodes.
  • Calculate the degree centrality of G_students using nx.degree_centrality(). Store the result as dcs.
  • Plot the histogram of degree centrality values.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# 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() 
Code bewerken en uitvoeren