how to calculate weighted transitivity with networkx in Python

653 Views Asked by At

As far as I know, the function in networkx for graph's transitivity is unweighted (shown as follow).

networkx.transitivity(G)  

I have tried it on a weighted graph, but in the results, only edges are considered. Is there any other way in networkx to calculate weighted transitivity? Besides, I only find the way in R, but I know nothing about R.

1

There are 1 best solutions below

1
cookesd On

As you stated, the networkx.transitivity function computes an unweighted transitivity measure for the whole graph. If you're referencing the weighted transitivity option from the R igraph package it doesn't look like networkx directly implements this calculation. However there is a function networkx.clustering(G, nodes=None, weight=None) (docs) that calculates a similar metric, but the formula aren't the same.

If you're looking for a python implementation of the formula from the igraph R package, you can also look into the python implementation of igraph which has a graph class with functions that compute local and global weighted transitivity (docs)