#はじめに
networkxとはpythonでグラフ・ネットワークを扱える便利なパッケージです。
Python 3.8.3
networkx 2.4
#データセット
##1. Zachary’s Karate Club graph
ノード数:34
エッジ数:78
論文:Zachary W. (1977). An information flow model for conflict and fission in small groups. Journal of Anthropological Research, 33, 452-473.
import networkx as nx
G = nx.karate_club_graph()
##2.Davis Southern women social network.
ノード数:32
エッジ数:89
論文:Breiger R. (1974). The duality of persons and groups. Social Forces, 53, 181-190.
import networkx as nx
G = nx.davis_southern_women_graph()
##3.football
ノード数:115
エッジ数:613
論文:Girvan, Michelle, and Mark EJ Newman. "Community structure in social and biological networks." Proceedings of the national academy of sciences 99.12 (2002): 7821-7826.
import urllib.request as urllib
import io
import zipfile
import matplotlib.pyplot as plt
import networkx as nx
url = "http://www-personal.umich.edu/~mejn/netdata/football.zip"
sock = urllib.urlopen(url) # open URL
s = io.BytesIO(sock.read()) # read into BytesIO "file"
sock.close()
zf = zipfile.ZipFile(s) # zipfile object
txt = zf.read("football.txt").decode() # read info file
gml = zf.read("football.gml").decode() # read gml data
# throw away bogus first line with # from mejn files
gml = gml.split("\n")[1:]
G = nx.parse_gml(gml) # parse gml data