这个Python库助你发现网络图的社区结构
小詹学Python
共 3664字,需浏览 8分钟
·
2021-03-05 12:18
来源:机器之心
熟知社区发现算法,你不能错过这个 Python 库。它涵盖 Louvain 算法、Girvan-Newman 算法等多种社区发现算法,还具有可视化功能。
Louvain 算法
Girvan-Newman 算法
层次聚类
谱聚类
Bron-Kerbosch 算法
$ pip install communities
louvain_method(adj_matrix : numpy.ndarray, n : int = None) -> list
from communities.algorithms import louvain_methodad
j_matrix = [...]
communities, _ = louvain_method(adj_matrix)
girvan_newman(adj_matrix : numpy.ndarray, n : int = None) -> list
from communities.algorithms import girvan_newman
adj_matrix = [...]
communities, _ = girvan_newman(adj_matrix)
hierarchical_clustering(adj_matrix : numpy.ndarray, metric : str = "cosine", linkage : str = "single", n : int = None) -> list
from communities.algorithms import hierarchical_clustering
adj_matrix = [...]
communities = hierarchical_clustering(adj_matrix, metric="euclidean", linkage="complete")
spectral_clustering(adj_matrix : numpy.ndarray, k : int) -> list
from communities.algorithms import spectral_clustering
adj_matrix = [...]
communities = spectral_clustering(adj_matrix, k=5)
bron_kerbosch(adj_matrix : numpy.ndarray, pivot : bool = False) -> list
from communities.algorithms import bron_kerbosch
adj_matrix = [...]
communities = bron_kerbosch(adj_matrix, pivot=True)
draw_communities(adj_matrix : numpy.ndarray, communities : list, dark : bool = False, filename : str = None, seed : int = 1)
from communities.algorithms import louvain_method
from communities.visualization import draw_communities
adj_matrix = [...]
communities, frames = louvain_method(adj_matrix)
draw_communities(adj_matrix, communities)
louvain_animation(adj_matrix : numpy.ndarray, frames : list, dark : bool = False, duration : int = 15, filename : str = None, dpi : int = None, seed : int = 2)
from communities.algorithms import louvain_method
from communities.visualization import louvain_animation
adj_matrix = [...]
communities, frames = louvain_method(adj_matrix)
louvain_animation(adj_matrix, frames)
评论