度中心性算法可用于查找图中的流行节点。它可以应用于加权图或未加权图。在加权情况下,算法计算图中每个节点的节点相邻关系的所有正权重的总和。忽略非正权重。
图的建立过程在专栏的其他文章中,不再赘述。
可以先看这个链接建立图
https://blog.csdn.net/m0_46371988/article/details/123986388?spm=1001.2014.3001.5501
首先给这个图命名
Graph是图的名字,Location是结点,ROAD是边。REVERSE,倒置,找入度最多的点。cost是边的权重那个属性。
CALL gds.graph.project(
'Graph',
'Location',
{
ROAD: {
orientation: 'REVERSE',
properties: ['cost']
}
}
)
如果节点和边比较多的话:
```python
CALL gds.graph.project(
'mygraph',
['users','genres','movies','occupation'],
['hasOccupation','rated','hasGenre']
)
测试一下内存
```python
CALL gds.degree.write.estimate('Graph', { writeProperty: 'degree' })
YIELD nodeCount, relationshipCount, bytesMin, bytesMax, requiredMemory
度中心性计算。前两句和都不需要改。第三句话注意name,和ROAD是边。第四句话也注意一下。
CALL gds.degree.stream('Graph')
YIELD nodeId, score
RETURN gds.util.asNode(nodeId).name AS name, score AS ROAD
ORDER BY ROAD DESC, name DESC
官方原文档
https://neo4j.com/docs/graph-data-science/current/algorithms/degree-centrality/