How to interpret nx.jaccard_coefficient in NetworkX?

Viewed 1339

The example code on NetworkX website is below (modified the last line):

>>> import networkx as nx  
>>> G = nx.complete_graph(5)  
>>> preds = nx.jaccard_coefficient(G, [(0, 1), (2, 3)])  
>>> for u, v, p in press: 
          ...  '(%d, %d) -> %.8f' % (u, v, p) 
          ... '(0, 1) -> 0.60000000'  
             '(2, 3) -> 1.20000000' # I modified this to make my point

I'm having trouble interpreting the scores. Does this mean (0, 1) shouldn't be connected but (2, 3) should? How should I convert these into 0's and 1's, where 1 is "yes, create a link", and 0 is "no, don't create a link"? For example, if I'd apply a threshold, would that be a legitimate approach? Should I put an unsupervised method on top of the scores to convert them into 0's and 1's?

What's the standard usage?

Edit: basically what I'm asking is, to get an accuracy score, we need 0's and 1's, and is there a standard for doing this score-to-binary conversion, or does everybody use a supervised/unsupervised machine learning method?

1 Answers

The jaccard coefficient is a similarity measure that finds the intersection over union of the input sets. In this case, we're doing exactly the same, having nodes as input sets.

By inspecting the source code, we have that the intersection is defined as the amount of common neighbours both nodes in a tuple will share. The union, the union of nodes with which they have connections:

cnbors = list(nx.common_neighbors(G, u, v))
union_size = len(set(G[u]) | set(G[v])) 

Then the jaccard similarity is obtained as:

len(cnbors) / union_size

So the higher the resulting value, the more common neighbors both nodes have with respect to their amount of connections, hence the more similar will these nodes be. And in terms of link predictability, this is translated to a higher likelihood of those two nodes being connected.

Related