karate_club module¶
- karate_club.karate_club_comp()[source]¶
Compare Louvain and Girvan-Newman community detection on the Zachary Karate Club graph.
This function applies Louvain and Girvan-Newman algorithms to the Zachary Karate Club graph to detect communities. It evaluates both methods using:
Modularity: Measures the strength of the community structure.
Adjusted Rand Index (ARI): Measures clustering accuracy compared to the ground truth.
The function prints the modularity and ARI scores for both methods and returns them.
- Returns:
A tuple containing: - louvain_modularity (float): Modularity score for Louvain clustering. - louvain_ari (float): ARI score for Louvain clustering. - gn_modularity (float): Modularity score for Girvan-Newman clustering. - gn_ari (float): ARI score for Girvan-Newman clustering.
- Return type:
tuple(float, float, float, float)
- karate_club.karate_club_rf()[source]¶
This function runs a series of tests on Zachary’s Karate Club graph (see https://doi.org/10.1086/jar.33.4.3629752) to compute the Ollivier-Ricci curvature, perform Ricci flow, and evaluate the modularity and accuracy after surgery.
Steps: 1. Load the Karate Club graph. 2. Compute the Ollivier-Ricci curvature of the graph. 3. Apply Ricci flow to the graph. 4. Compute modularity and ARI (Adjusted Rand Index) based on the cutoff parameter. 5. Perform edge surgery based on a user-defined threshold (i.e. the chosen cutoff). 6. Detect communities as connected components of the resulting graph. 7. Draw and save visualizations for each of the steps.
The resulting images and accuracy plots are saved to a directory called ‘KarateClubResults’.
- Returns:
A tuple containing: - best_mod (float): Modularity value corrensponding to highest ari. - best_ari (float): Highest Adjusted Rand Index obtained applying Ricci Flow.
- Return type:
tuple(float, float)