<jupyter_start><jupyter_text>Betweeness CentralityBetweenness centrality measuresCode source: https://networkx.org/documentation/latest/auto_examples/algorithms/plot_betweenness_centrality.htmlMultigraph is not implemented for the connected components, so we use undirected graph.<jupyter_code>import networkx as nx
import matplotlib.pyplot as plt
import pandas as pd
%run ./prepare_data.ipynb
G = nx.from_pandas_edgelist(df_raw, 'Player', 'Guess',)


# largest connected component
components = nx.connected_components(G)
largest_component = max(components, key=len)
H = G.subgraph(largest_component)

# compute centrality
centrality = nx.betweenness_centrality(H, k=10, endpoints=True)

# compute community structure
lpc = nx.community.label_propagation_communities(H)
community_index = {n: i for i, com in enumerate(lpc) for n in com}

#### draw graph ####
fig, ax = plt.subplots(figsize=(20, 15))
pos = nx.spring_layout(H, k=0.15, seed=4572321)
node_color = [community_index[n] for n in H]
node_size = [v * 20000 for v in centrality.values()]
nx.draw_networkx(
    H,
    pos=pos,
    with_labels=True,
    node_color=node_color,
    node_size=node_size,
    arrowsize = 20,
    font_size = 24,
    font_weight = "bold",
    #edge_color="gainsboro",
    alpha=0.4,
)

# Title/legend
font = {"color": "k", "fontweight": "bold", "fontsize": 20}
ax.set_title("Guesses Network", font)
# Change font color for legend
font["color"] = "r"

ax.text(
    0.90,
    0.10,
    "node color = community structure",
    horizontalalignment="center",
    transform=ax.transAxes,
    fontdict=font,
)
ax.text(
    0.90,
    0.06,
    "node size = betweeness centrality",
    horizontalalignment="center",
    transform=ax.transAxes,
    fontdict=font,
)

# Resize figure for label readibility
ax.margins(0.1, 0.05)
fig.tight_layout()
plt.axis("off")
plt.show()<jupyter_output>ERROR:root:Internal Python error in the inspect module.
Below is the traceback from this internal error.
{'fraction_non_alphanumeric': 0.11947127605490594, 'fraction_numerical': 0.02338586680223691, 'mean_word_length': 4.839762611275964, 'pattern_counts': {'":': 3, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '312448', 'license': 'Apache-2.0', 'n_tokens_mistral': 727, 'n_tokens_neox': 679, 'n_words': 167, 'path': 'notebooks/plot_betweenness_centrality.ipynb', 'repo_name': 'NLeSC/balconaz', 'size': '1967'}