local_and_global_consistency#
- local_and_global_consistency(G, alpha=0.99, max_iter=30, label_name='label')[源]#
基于局部和全局一致性的节点分类
计算 Zhou 等人提出的局部和全局一致性算法的函数。
- 参数:
- GNetworkX 图
- alphafloat
钳位因子
- max_iterint
允许的最大迭代次数
- label_namestring
要预测的目标标签名称
- 返回值:
- predictedlist
一个长度为
len(G)
的列表,包含每个节点的预测标签。
- 抛出:
- NetworkXError
如果
G
中没有节点的属性为label_name
。
参考文献
Zhou, D., Bousquet, O., Lal, T. N., Weston, J., & Schölkopf, B. (2004). Learning with local and global consistency. Advances in neural information processing systems, 16(16), 321-328.
示例
>>> from networkx.algorithms import node_classification >>> G = nx.path_graph(4) >>> G.nodes[0]["label"] = "A" >>> G.nodes[3]["label"] = "B" >>> G.nodes(data=True) NodeDataView({0: {'label': 'A'}, 1: {}, 2: {}, 3: {'label': 'B'}}) >>> G.edges() EdgeView([(0, 1), (1, 2), (2, 3)]) >>> predicted = node_classification.local_and_global_consistency(G) >>> predicted ['A', 'A', 'B', 'B']