LoslegenKostenlos loslegen

Degree centrality distribution

The degree of a node is the number of neighbors that it has. The degree centrality is the number of neighbors divided by all possible neighbors that it could have. Depending on whether self-loops are allowed, the set of possible neighbors a node could have could also include the node itself.

The nx.degree_centrality(G) function returns a dictionary, where the keys are the nodes and the values are their degree centrality values.

The degree distribution degrees you computed in the previous exercise using the list comprehension has been pre-loaded.

Diese Übung ist Teil des Kurses

Introduction to Network Analysis in Python

Kurs anzeigen

Anleitung zur Übung

  • Compute the degree centrality of the Twitter network T.
  • Using plt.hist(), plot a histogram of the degree centrality distribution of T. This can be accessed using list(deg_cent.values()).
  • Plot a histogram of the degree distribution degrees of T. This is the same list you computed in the last exercise.
  • Create a scatter plot with degrees on the x-axis and the degree centrality distribution list(deg_cent.values()) on the y-axis.

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# Import matplotlib.pyplot
import matplotlib.pyplot as plt

# Compute the degree centrality of the Twitter network: deg_cent
deg_cent = ____

# Plot a histogram of the degree centrality distribution of the graph.
plt.figure()
____
plt.show()

# Plot a histogram of the degree distribution of the graph
plt.figure()
____
plt.show()

# Plot a scatter plot of the centrality distribution and the degree distribution
plt.figure()
____
plt.show()
Code bearbeiten und ausführen