Approfondimento - Rete di Twitter parte II
Ora farai un approfondimento analogo sulla betweenness centrality! Solo qualche suggerimento per aiutarti: ricorda che la betweenness centrality si calcola con nx.betweenness_centrality(G).
Questo esercizio fa parte del corso
Introduzione all'analisi delle reti in Python
Istruzioni dell'esercizio
- Scrivi una funzione
find_node_with_highest_bet_cent(G)che restituisce il o i nodi con la betweenness centrality più alta.- Calcola la betweenness centrality di
G. - Calcola il massimo della betweenness centrality usando la funzione
max()sulist(bet_cent.values()). - Itera sul dizionario della betweenness centrality,
bet_cent.items(). - Se il valore di betweenness centrality
vdel nodo correntekè uguale amax_bc, aggiungilo all'insieme dei nodi.
- Calcola la betweenness centrality di
- Usa la tua funzione per trovare il o i nodi con la betweenness centrality più alta in
T. - Scrivi un'istruzione di asserzione per verificare che hai trovato il nodo giusto. Questo è già stato fatto per te, quindi fai clic su "Invia risposta" per vedere il risultato!
Esercizio pratico interattivo
Prova a risolvere questo esercizio completando il codice di esempio.
# Define find_node_with_highest_bet_cent()
def find_node_with_highest_bet_cent(G):
# Compute betweenness centrality: bet_cent
bet_cent = ____
# Compute maximum betweenness centrality: max_bc
max_bc = ____
nodes = set()
# Iterate over the betweenness centrality dictionary
for k, v in ____:
# Check if the current value has the maximum betweenness centrality
if ____ == ____:
# Add the current node to the set of nodes
____
return nodes
# Use that function to find the node(s) that has the highest betweenness centrality in the network: top_bc
top_bc = ____
print(top_bc)
# Write an assertion statement that checks that the node(s) is/are correctly identified.
for node in top_bc:
assert nx.betweenness_centrality(T)[node] == max(nx.betweenness_centrality(T).values())