GiulioRossetti / f1-communities

A novel approach to evaluate community detection algorithms on ground truth
doi:10.1007/978-3-319-30569-1_10
GNU General Public License v3.0
21 stars 7 forks source link

Error in running example code #4

Closed massimocallisto closed 6 months ago

massimocallisto commented 6 months ago

Hi Giulio,

I'm testing the library but an error occurred in the provided example.

Traceback (most recent call last):
  File "/Users/USER/testnf1/main.py", line 15, in <module>
    results = nf.summary()
  File "/Users/USER/testnf1/venv/lib/python3.10/site-packages/nf1/NF1_class.py", line 221, in summary
    mean, std, mx, mn, mode = self.get_f1()
  File "/Users/USER/testnf1/venv/lib/python3.10/site-packages/nf1/NF1_class.py", line 34, in get_f1
    scipy.stats.mode(f1_list)[0][0])
IndexError: invalid index to scalar variable.

I'm using a MackBook Air M2, python 3.10.11 The same error is given in Ubuntu 22.04LTS 64bit Intel, python 3.10.12

Here the installed packages:

Package         Version
--------------- -----------
contourpy       1.2.1
cycler          0.12.1
fonttools       4.51.0
kiwisolver      1.4.5
matplotlib      3.8.4
networkx        3.3
nf1             0.0.4
numpy           1.26.4
packaging       24.0
pandas          2.2.2
pillow          10.3.0
pip             23.0.1
pyparsing       3.1.2
python-dateutil 2.9.0.post0
pytz            2024.1
scipy           1.13.0
setuptools      65.5.0
six             1.16.0
tzdata          2024.1

The code is the one from the README file:

from nf1 import NF1
import networkx as nx
from networkx.algorithms import community

g = nx.karate_club_graph()

kclique = list(community.k_clique_communities(g, 4))
kcoms = [tuple(x) for x in kclique]

lp = list(community.label_propagation_communities(g))
lpcoms = [tuple(x) for x in lp]

# Computing the NF1 scores and statistics
nf = NF1(lpcoms, kcoms)
results = nf.summary()
print(results['scores'])
print(results['details'])

# Visualising the Precision-Recall density scatter-plot
nf.plot()

Thank you

Massimo

GiulioRossetti commented 6 months ago

Hi @massimocallisto, the error is probably due to some issue with the scipy version installed in your system - which probably differs from the one originally requested by the package.

My suggestion is to use our library dedicated to community detection CDlib instead of this older package that has not been maintained in years.

There you can find algorithms, visualization facilities and also evaluation and comparison functions (even nf1).

Best, Giulio

massimocallisto commented 6 months ago

Hi Giulio, Actually I started from CDlib which actually depends on this package, if I'm right.  The same problem happens in that case when running the code below:

from cdlib import evaluation, algorithms
g = nx.karate_club_graph()
louvain_communities = algorithms.louvain(g)
leiden_communities = algorithms.leiden(g)
evaluation.f1(louvain_communities,leiden_communities)

Thanks

Massimo

GiulioRossetti commented 6 months ago

Hi Massimo, I double checked: the issue is tied to a changed signature (and behavior) of a Scipy method used by NF1.

To avoid cascading effects and dependency version nightmares I just integrated a patched version of NF1 directly in the CDlib master branch (probably I'll release a new version of the package within this week).

Now you should be able to use it without additional issues by installing cdlib with

pip install git+https://github.com/GiulioRossetti/cdlib

Best, Giulio

massimocallisto commented 6 months ago

Dear Giulio, Thank you for the patch. So, I will definitely move to cdlib.

Regards

Massimo