Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Visualizing the output of a hierarchical clustering #211

Open
dror-kris opened this issue May 31, 2022 · 2 comments
Open

Visualizing the output of a hierarchical clustering #211

dror-kris opened this issue May 31, 2022 · 2 comments

Comments

@dror-kris
Copy link

I'm trying to utilize the Paris algorithm for hierarchical community detection.

When I attempt to visualize the network and communities, I encounter the following error:

KeyError                                  Traceback (most recent call last)
~\anaconda3\envs\cdlib\lib\site-packages\networkx\drawing\nx_pylab.py in draw_networkx_nodes(G, pos, nodelist, node_size, node_color, node_shape, alpha, cmap, vmin, vmax, ax, linewidths, edgecolors, label, margins)
    455     try:
--> 456         xy = np.asarray([pos[v] for v in nodelist])
    457     except KeyError as err:

~\anaconda3\envs\cdlib\lib\site-packages\networkx\drawing\nx_pylab.py in <listcomp>(.0)
    455     try:
--> 456         xy = np.asarray([pos[v] for v in nodelist])
    457     except KeyError as err:

KeyError: 656

The above exception was the direct cause of the following exception:

NetworkXError                             Traceback (most recent call last)
<ipython-input-62-3db2159df5b2> in <module>
----> 1 viz.plot_network_clusters(G, coms)

c:\users\work\src\cdlib\cdlib\viz\networks.py in plot_network_clusters(graph, partition, position, figsize, node_size, plot_overlaps, plot_labels, cmap, top_k, min_size)
    113         )
    114     )
--> 115     fig = nx.draw_networkx_nodes(
    116         graph, position, node_size=node_size, node_color="w", nodelist=filtered_nodelist
    117     )

~\anaconda3\envs\cdlib\lib\site-packages\networkx\drawing\nx_pylab.py in draw_networkx_nodes(G, pos, nodelist, node_size, node_color, node_shape, alpha, cmap, vmin, vmax, ax, linewidths, edgecolors, label, margins)
    456         xy = np.asarray([pos[v] for v in nodelist])
    457     except KeyError as err:
--> 458         raise nx.NetworkXError(f"Node {err} has no position.") from err
    459 
    460     if isinstance(alpha, Iterable):

NetworkXError: Node 656 has no position.

Should I be using an alternative visualization method?
On the github page for the Paris package (https://github.com/tbonald/paris), I see the following visualization:

from utils import plot_dendrogram

plot_dendrogram(D)

Additionally, when attempting to map the partition using coms.to_node_community_map() I lose the hierarchies between communities - is there a better way to work with the partition output?

Thanks!

@github-actions
Copy link

Thanks for submitting your first issue!

@paulgay
Copy link

paulgay commented Feb 8, 2024

Hi, same issue here,
did you find any solution ?
I notice that networkx enable access to the hierarchy with the louvain algorithm

dendogram =  nx.algorithms.community.louvain.louvain_partitions(G, resolution=resolution)
coms = {}
for level, p in enumerate(dendogram):
    print(level, len(p))
    coms[level] = p

From what I see the paris function of cdlib returns only a flat list in the NodeClustering. Am i missing something here ?
Thanks for your answer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants