Conductance metric
Glossary
- Directed
-
Directed trait. The algorithm is well-defined on a directed graph.
- Directed
-
Directed trait. The algorithm ignores the direction of the graph.
- Directed
-
Directed trait. The algorithm does not run on a directed graph.
- Undirected
-
Undirected trait. The algorithm is well-defined on an undirected graph.
- Undirected
-
Undirected trait. The algorithm ignores the undirectedness of the graph.
- Heterogeneous nodes
-
Heterogeneous nodes fully supported. The algorithm has the ability to distinguish between nodes of different types.
- Heterogeneous nodes
-
Heterogeneous nodes allowed. The algorithm treats all selected nodes similarly regardless of their label.
- Heterogeneous relationships
-
Heterogeneous relationships fully supported. The algorithm has the ability to distinguish between relationships of different types.
- Heterogeneous relationships
-
Heterogeneous relationships allowed. The algorithm treats all selected relationships similarly regardless of their type.
- Weighted relationships
-
Weighted trait. The algorithm supports a relationship property to be used as weight, specified via the relationshipWeightProperty configuration parameter.
- Weighted relationships
-
Weighted trait. The algorithm treats each relationship as equally important, discarding the value of any relationship weight.
Introduction
Conductance is a metric that allows you to evaluate the quality of a community detection.
Relationships of nodes in a community C
connect to nodes either within C
or outside C
.
The conductance is the ratio between relationships that point outside C
and the total number of relationships of C
.
The lower the conductance, the more "well-knit" a community is.
It was shown by Yang and Leskovec in the paper "Defining and Evaluating Network Communities based on Ground-truth" that conductance is a very good metric for evaluating actual communities of real world graphs.
The algorithm runs in time linear to the number of relationships in the graph.
Syntax
This section covers the syntax used to execute the Conductance algorithm in each of its execution modes. We are describing the named graph variant of the syntax. To learn more about general syntax variants, see Syntax overview.
CALL gds.conductance.stream(
graphName: String,
configuration: Map
) YIELD
community: Integer,
conductance: Float
Name | Type | Default | Optional | Description |
---|---|---|---|---|
graphName |
String |
|
no |
The name of a graph stored in the catalog. |
configuration |
Map |
|
yes |
Configuration for algorithm-specifics and/or graph filtering. |
Name | Type | Default | Optional | Description |
---|---|---|---|---|
List of String |
|
yes |
Filter the named graph using the given node labels. Nodes with any of the given labels will be included. |
|
List of String |
|
yes |
Filter the named graph using the given relationship types. Relationships with any of the given types will be included. |
|
Integer |
|
yes |
The number of concurrent threads used for running the algorithm. |
|
String |
|
yes |
An ID that can be provided to more easily track the algorithm’s progress. |
|
Boolean |
|
yes |
If disabled the progress percentage will not be logged. |
|
String |
|
yes |
Name of the relationship property to use as weights. If unspecified, the algorithm runs unweighted. |
|
communityProperty |
String |
|
no |
The node property that holds the community ID as an integer for each node. Note that only non-negative community IDs are considered valid and will have their conductance computed. |
Name | Type | Description |
---|---|---|
community |
Integer |
Community ID. |
conductance |
Float |
Conductance of the community. |
Only non-negative community IDs are valid for identifying communities. Nodes with a negative community ID will only take part in the computation to the extent that they are connected to nodes in valid communities, and thus contribute to those valid communities' outward relationship counts. |
Examples
All the examples below should be run in an empty database. The examples use Cypher projections as the norm. Native projections will be deprecated in a future release. |
In this section we will show examples of running the Conductance algorithm on a concrete graph. The intention is to illustrate what the results look like and to provide a guide in how to make use of the algorithm in a real setting. We will do this on a small social network graph of a handful nodes connected in a particular pattern. The example graph looks like this:
CREATE
(nAlice:User {name: 'Alice', seed: 42}),
(nBridget:User {name: 'Bridget', seed: 42}),
(nCharles:User {name: 'Charles', seed: 42}),
(nDoug:User {name: 'Doug'}),
(nMark:User {name: 'Mark'}),
(nMichael:User {name: 'Michael'}),
(nAlice)-[:LINK {weight: 1}]->(nBridget),
(nAlice)-[:LINK {weight: 1}]->(nCharles),
(nCharles)-[:LINK {weight: 1}]->(nBridget),
(nAlice)-[:LINK {weight: 5}]->(nDoug),
(nMark)-[:LINK {weight: 1}]->(nDoug),
(nMark)-[:LINK {weight: 1}]->(nMichael),
(nMichael)-[:LINK {weight: 1}]->(nMark);
This graph has two clusters of Users, that are closely connected.
Between those clusters there is one single edge.
The relationships that connect the nodes in each component have a property weight
which determines the strength of the relationship.
We can now project the graph and store it in the graph catalog.
We load the LINK
relationships with orientation set to UNDIRECTED
as this works best with the Louvain algorithm which we will use to create the communities that we evaluate using Conductance.
MATCH (source:User)
OPTIONAL MATCH (source)-[r:LINK]->(target:User)
RETURN gds.graph.project(
'myGraph',
source,
target,
{
sourceNodeProperties: source { .seed },
targetNodeProperties: target { .seed },
relationshipProperties: r { .weight }
},
{ undirectedRelationshipTypes: ['*'] }
)
We now run the Louvain algorithm to create a division of the nodes into communities that we can then evalutate.
myGraph
:CALL gds.louvain.mutate('myGraph', { mutateProperty: 'community', relationshipWeightProperty: 'weight' })
YIELD communityCount
communityCount |
---|
3 |
Now our in-memory graph myGraph
is populated with node properties under the key community
that we can set as input for our evaluation using Conductance.
The nodes are now assigned to communities in the following way:
name | community |
---|---|
"Alice" |
1 |
"Bridget" |
3 |
"Charles" |
3 |
"Doug" |
1 |
"Mark" |
5 |
"Michael" |
5 |
Please see the stream node properties procedure for how to obtain such an assignment table.
For more information about Louvain, see its algorithm page.
Stream
Since we now have a community detection, we can evaluate how good it is under the conductance metric. Note that we in this case we use the feature of relationships being weighted by a relationship property.
The Conductance stream procedure returns the conductance for each community. This allows us to inspect the results directly or post-process them in Cypher without any side effects.
For more details on the stream mode in general, see Stream.
stream
mode:CALL gds.conductance.stream('myGraph', { communityProperty: 'community', relationshipWeightProperty: 'weight' })
YIELD community, conductance
community | conductance |
---|---|
1 |
0.23076923076923078 |
3 |
0.5 |
5 |
0.2 |
We can see that the community of the weighted graph with the lowest conductance is community 5. This means that 5 is the community that is most "well-knit" in the sense that most of its relationship weights are internal to the community.