[docs]classKarateClubDataset(DGLDataset):r"""Karate Club dataset for Node Classification Zachary's karate club is a social network of a university karate club, described in the paper "An Information Flow Model for Conflict and Fission in Small Groups" by Wayne W. Zachary. The network became a popular example of community structure in networks after its use by Michelle Girvan and Mark Newman in 2002. Official website: `<http://konect.cc/networks/ucidata-zachary/>`_ Karate Club dataset statistics: - Nodes: 34 - Edges: 156 - Number of Classes: 2 Parameters ---------- transform : callable, optional A transform that takes in a :class:`~dgl.DGLGraph` object and returns a transformed version. The :class:`~dgl.DGLGraph` object will be transformed before every access. Attributes ---------- num_classes : int Number of node classes Examples -------- >>> dataset = KarateClubDataset() >>> num_classes = dataset.num_classes >>> g = dataset[0] >>> labels = g.ndata['label'] """def__init__(self,transform=None):super(KarateClubDataset,self).__init__(name="karate_club",transform=transform)defprocess(self):kc_graph=nx.karate_club_graph()label=np.asarray([kc_graph.nodes[i]["club"]!="Mr. Hi"foriinkc_graph.nodes]).astype(np.int64)label=F.tensor(label)g=from_networkx(kc_graph)g.ndata["label"]=labelself._graph=gself._data=[g]@propertydefnum_classes(self):"""Number of classes."""return2
[docs]def__getitem__(self,idx):r"""Get graph object Parameters ---------- idx : int Item index, KarateClubDataset has only one graph object Returns ------- :class:`dgl.DGLGraph` graph structure and labels. - ``ndata['label']``: ground truth labels """assertidx==0,"This dataset has only one graph"ifself._transformisNone:returnself._graphelse:returnself._transform(self._graph)
[docs]def__len__(self):r"""The number of graphs in the dataset."""return1