Warning

This documents an unmaintained version of NetworkX. Please upgrade to a maintained version and see the current NetworkX documentation.

networkx.algorithms.node_classification.hmn.harmonic_function

harmonic_function(G, max_iter=30, label_name='label')[source]

Node classification by Harmonic function

Parameters:
  • G (NetworkX Graph)
  • max_iter (int) – maximum number of iterations allowed
  • label_name (string) – name of target labels to predict
Raises:

NetworkXError if no nodes on G has label_name.

Returns:

predicted – Array of predicted labels

Return type:

array, shape = [n_samples]

Examples

>>> from networkx.algorithms import node_classification
>>> G = nx.path_graph(4)
>>> G.node[0]['label'] = 'A'
>>> G.node[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.harmonic_function(G)
>>> predicted
['A', 'A', 'B', 'B']

References

Zhu, X., Ghahramani, Z., & Lafferty, J. (2003, August). Semi-supervised learning using gaussian fields and harmonic functions. In ICML (Vol. 3, pp. 912-919).