local_and_global_consistency#

local_and_global_consistency(G, alpha=0.99, max_iter=30, label_name='label')[source]#

节点分类通过局部和全局一致性

用于计算Zhou等人提出的局部和全局一致性算法的函数。

Parameters:
GNetworkX 图
alpha浮点数

阻尼因子

max_iter整数

允许的最大迭代次数

label_name字符串

目标标签的名称,用于预测

Returns:
predicted列表

长度为 len(G) 的列表,包含每个节点的预测标签。

Raises:
NetworkXError

如果 G 中没有节点具有属性 label_name

References

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.

Examples

>>> 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']