Tutorial 1: Welcome to NetworkX

Status

Filled notebook: View filled on Github Open filled In Collab

Recordings: YouTube - Part 1
Author: Animesh Sachan

Welcome to our NetworkX tutorial for the Graph Machine Learning course at the IIT Kharagpur! The following notebook is meant to give an introduction to NetworkX, and get you setup for creating your own graphs and understanding them in depth. NetworkX is a Python package for the creation, manipulation, and study of the structure, dynamics, and functions of complex networks.

We are of course not the first ones to create tutorial on NetworkX. There are many great tutorials online, and on the official NetworkX website. Yet, we choose to create our own tutorial which is designed to give you the basics particularly necessary for the practicals, but still understand how NetworkX works under the hood. Over the next upcoming tutorials we will keep on exploring more features of NetworkX in the series of Jupyter notebook tutorials about Graph Machine Learning.

We will use a set of standard libraries that are often used in graph machine learning projects. If you are running this notebook on Google Colab, all libraries should be pre-installed. If you are running this notebook locally, make sure you have installed our gmlfa_cpu environment and have activated it.

[1]:
## Standard libraries
import os
import math
import numpy as np
import time

## Imports for plotting
import matplotlib.pyplot as plt
%matplotlib inline
from IPython.display import set_matplotlib_formats
set_matplotlib_formats('svg', 'pdf') # For export
from matplotlib.colors import to_rgba
import seaborn as sns
sns.set()

## Progress bar
from tqdm.notebook import tqdm
/var/folders/7s/7lj__0j916x78ltyhj647wgm0000gn/T/ipykernel_51391/3937499902.py:11: DeprecationWarning: `set_matplotlib_formats` is deprecated since IPython 7.23, directly use `matplotlib_inline.backend_inline.set_matplotlib_formats()`
  set_matplotlib_formats('svg', 'pdf') # For export

The Basics of NetworkX

We will start with reviewing the very basic concepts. As a prerequisite, we recommend to be familiar with the numpy package as most machine learning frameworks are based on very similar concepts. If you are not familiar with numpy yet, don’t worry: here is a tutorial to go through.

So, let’s start with importing NetworkX. The package is called networkx. As a first step, we can check its version:

[2]:
import networkx as nx
print('version', nx.__version__)
version 3.4.1
[ ]: