Triangles and cliques

This notebook illustrates clique counting and evaluation of the clustering coefficient of a graph.

[1]:
from IPython.display import SVG
[2]:
import numpy as np
[3]:
from sknetwork.data import karate_club
from sknetwork.topology import Triangles, Cliques
from sknetwork.visualization import svg_graph

Triangles

[4]:
graph = karate_club(metadata=True)
adjacency = graph.adjacency
position = graph.position
[5]:
image = svg_graph(adjacency, position)
SVG(image)
[5]:
../../_images/tutorials_topology_cliques_7_0.svg
[6]:
triangles = Triangles()
[7]:
triangles.fit_transform(adjacency)
[7]:
45
[8]:
np.round(triangles.clustering_coef_, 2)
[8]:
0.26

Cliques

[9]:
cliques = Cliques(4)
[10]:
cliques.fit_transform(adjacency)
[10]:
11