:sparkler: Network/Graph Analysis with NetworkX in Python. Topics range from network types, statistics, link prediction measures, and community detection.
Graph-Analysis-with-NetworkX
Graph Analysis with NetworkXDependencies:
Theenvironment.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:
- Undirected graph
- Directed graph
- Signed graph
- Weighted graph
- Multigraph
- Bipartite Graph
- 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: 
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:
- Triadic Closer:
- Distance Measures:

Karate Network with Center 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:
- Connectivity:
- Robustness:

Mutual Connection:
Min Node Cut Example:
Min Edge Cut Example:
Click here to see the notebook part 3
Notebook 3 part 3 covers how to calculate and interpret graph statistics for the following topic:
- Centreality (Node Importance):
- Centrality Ranking by Averging Centrality Measures
Summary Table for Centrality Measures:
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:
- Non-community Based Measures
Visualizing the 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
- Community Detection Algorithms:
Visualizing the community partition by Louvain Algorithm:
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:
