三角形和团

此笔记本说明了团计数和图的聚类系数评估。

[1]:
from IPython.display import SVG
[2]:
import numpy as np
[3]:
from sknetwork.data import karate_club
from sknetwork.topology import count_triangles, get_clustering_coefficient, count_cliques
from sknetwork.visualization import visualize_graph

三角形

[4]:
graph = karate_club(metadata=True)
adjacency = graph.adjacency
position = graph.position
[5]:
# graph
image = visualize_graph(adjacency, position)
SVG(image)
[5]:
../../_images/tutorials_topology_cliques_7_0.svg
[6]:
# number of triangles
count_triangles(adjacency)
[6]:
45
[7]:
# coefficient of clustering
np.round(get_clustering_coefficient(adjacency), 2)
[7]:
0.26

[8]:
# number of 4-cliques
count_cliques(adjacency, 4)

[8]:
11