local_and_global_consistency¶
- local_and_global_consistency(G, alpha=0.99, max_iter=30, label_name='label')[source]¶
Node classification by Local and Global Consistency
- Parameters
- GNetworkX Graph
- alphafloat
Clamping factor
- max_iterint
Maximum number of iterations allowed
- label_namestring
Name of target labels to predict
- Returns
- predictedlist
List of length
len(G)
with the predicted labels for each node.
- Raises
- NetworkXError
If no nodes in
G
have attributelabel_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']