Find nodes with top degree centralities
In this exercise, you'll take a deeper dive to see whether there's anything interesting about the most connected students in the network. First off, you'll find the cluster of students that have the highest degree centralities. This result will be saved for the next plotting exercise.
Bu egzersiz
Intermediate Network Analysis in Python
kursunun bir parçasıdırEgzersiz talimatları
- Get the top 5 unique degree centrality scores. To do this, use the
sorted()function, in which the first argument is the set of degree centrality values of G (because you want unique degree centralities), and the second argument isreverse=True, to ensure that it is sorted in descending order. To limit the results to the top 5 scores, add in appropriate slicing to the end of the statement. Also, remember to use.values()on the returned degree centrality results! - Create list of nodes that have the top 5 highest overall degree centralities. To do this:
- Iterate over the dictionary of degree centrality scores using the
.items()method onnx.degree_centrality(G). - If
dcis intop_dcs, then append the nodento thetop_connectedlist.
- Iterate over the dictionary of degree centrality scores using the
- Print the number of nodes that share the top 5 degree centrality scores (
top_connected) usinglen().
Uygulamalı interaktif egzersiz
Bu örnek kodu tamamlayarak bu egzersizi bitirin.
# Get the top 5 unique degree centrality scores: top_dcs
top_dcs = ____(set(____), reverse=True)[____:____]
# Create list of nodes that have the top 5 highest overall degree centralities
top_connected = []
for n, dc in ____:
if ____ in ____:
____
# Print the number of nodes that share the top 5 degree centrality scores
print(____)