/Graph-Analysis-with-NetworkX

:sparkler: Network/Graph Analysis with NetworkX in Python. Topics range from network types, statistics, link prediction measures, and community detection.

Primary LanguageJupyter Notebook

Graph-Analysis-with-NetworkX

Graph Analysis with NetworkX

Dependencies:

The environment.yml YAML file in the root folder has the exact conda environment I used for this project.
The requirements.txt text file in the root folder has the exact Python environment I used for this project.

  • Option 1: Run below with conda to create a new environment to have the exact same environment I used for running the notebooks:
    conda env create -f environment.yml will create a conda environment called network_analysis.
    Then, you can run conda env list to view your existing environments.
    You can run conda activate network_analysis to use the new environment.

  • Option 2: If you don't want to use conda to create a environment, you can try install Python packages I used with the following command:
    pip install -r requirements.txt

Notebook 1: Graph Types:

Click here to see the notebook

This notebook covers how to create the following graphs using NetworkX:

  1. Undirected graph
  2. Directed graph
  3. Signed graph
  4. Weighted graph
  5. Multigraph
  6. Bipartite Graph
  7. Projected Graph

Notebook 2: Spring Layout:

Click here to see the notebook

This notebook covers how to create visualization using the spring layout in NetworkX for Genshin Impact character network:
genshin_impact_character_network

Notebook 3: Graph Statistics:

Click here to see the notebook part 1

Notebook 3 part 1 covers how to calculate and interpret graph statistics for the following topic:

  1. Triadic Closer:
    • Local Clustering Coefficient (LCC)
    • Global Clustering Coefficient (GCC): Average LCC and Transitivity
  2. Distance Measures:
    • Average Distance (Average Shortest Path Length)
    • Eccentricity
    • Diameter
    • Radius
    • Center
    • Periphery

Karate Network

Karate Network with Center Visualized:

Karate Network with Center Visualized

Karate Network with Periphery Visualized:

Karate Network with Periphery Visualized

Click here to see the notebook part 2

Notebook 3 part 2 covers how to calculate and interpret graph statistics for the following topic:

  1. Connectivity:
    • Strongly Connected
    • Weakly Connected
  2. Robustness:
    • Density
    • Node Connectivity
    • Min Node CUt
    • Edge Connectivity
    • Min Edge Cut
    • Isolates

Sucrose Neighbors

Mutual Connection:

Mutual Connection

Min Node Cut Example:

Min Node Cut

Min Edge Cut Example:

Min Edge Cut

Click here to see the notebook part 3

Notebook 3 part 3 covers how to calculate and interpret graph statistics for the following topic:

  1. Centreality (Node Importance):
    • Degree Centrality
    • CLoseness Centrality
    • Node Betweenness Centrality
    • Edge Betweenness Centrality
    • PageRank Centrality with PageRank Algorithm
    • Auth and Hub Centrality with HITS Algorithm
  2. Centrality Ranking by Averging Centrality Measures

Summary Table for Centrality Measures:

Summary Table for Centrality Measures

Final Output of Averaging Centrality Ranking:

Final Output of Averaging Centrality Ranking

Notebook 4: Graph Link Prediction:

Click here to see the notebook part 1

Notebook 4 part 1 covers how to calculate and interpret the below common link prediction features:

  1. Non-community Based Measures
    • The Number of Common Neighbors
    • Jaccard Coefficient
    • Resource Allocation Index
    • Adamic-Adar Index
    • Preferential Attachment

Visualizing the Common Neighbors for Potential Connection between Node 2 and Node 33

Common Neighbors for Potential Connection between Node 2 and Node 33

Notebook 5: Graph Community Detection Algorithms:

Click here to see the notebook

Notebook 5 covers how to use implemented community detection algorithms in NetworkX, python-louvain, and leidenalg

  1. Community Detection Algorithms:
    • Girvan-Newman
    • Label-Propagation
    • Louvain
    • Leiden

Visualizing the community partition by Louvain Algorithm:

Louvain Algorithm Partition Output

Notebook 6: Comparison of Louvain and Leiden for Community Detection:

Click here to see the notebook

Stanford Network Analysis Project dataset is used for comparing performance: DBLP collaboration network

node total edge total Average clustering coefficient
317,080 1,049,866 0.6324

Notebook 6 compares the community detection results using Louvain and Leiden algorithms in open source Python package called python-louvain and leidenalg. The notebook will highlight the disadvanatge sof Louvain algorithm and demonstrate why Leiden may be the algorithm you want to use for community detection.

Louvain Leiden
Modularity 0.821751 0.830028
Louvain Leiden
Disconnected Community 5 0

Visualizing the disconnected community partition by Louvain Algorithm:

Louvain Algorithm Partition Disconnected Output