总结:使用 Neo4j GDS 库,我想对我的图形数据进行聚类。这里我分享一个数据的测试示例。数据中的值(我希望)是图节点的属性。我正在按以下步骤进行分析:
我在这里提供数据示例和 Cypher 查询,没有来自投影。
我的数据以 csv 格式提供:
scene_id,obj_type,lane
1,1,1
1,2,3
2,3,2
3,4,1
3,1,3
4,1,2
4,3,1
5,2,2
6,4,3
6,3,1
6,1,2
在Cypher中查询加载和创建节点:
LOAD CSV WITH HEADERS FROM 'file:///modified_data.csv' AS row
MERGE (image:Image {scene_id: toFloat(row['scene_id'])})
MERGE (object:Object {obj_type: toFloat(row['obj_type'])})
MERGE (lane:Lane {direction: toFloat(row['lane'])})
MERGE (image)-[:CONTAINS]->(object)
MERGE (object)-[:IN_LANE]->(lane)
查询导致错误的图形投影:
CALL gds.graph.project(
'imgraph1',
{
Image: {properties: 'scene_id},
Object: {properties: 'obj_type'},
Lane: {properties: 'direction'}
},
['CONTAINS', 'IN_LANE']
)
上面给出的查询的输出看起来不错:
Graph Name: imgraph1
Node Count: 13
Relationship Count: 20
nodeProjection: {'Lane': {'label': 'Lane', 'properties': {'direction': {'property': 'direction', 'defaultValue': None}}}, 'Image': {'label': 'Image', 'properties': {'scene_id': {'property': 'scene_id', 'defaultValue': None}}}, 'Object': {'label': 'Object', 'properties': {'obj_type': {'property': 'obj_type', 'defaultValue': None}}}}
现在是嵌入查询:
CALL gds.fastRP.mutate(
'imgraph1',
{
embeddingDimension: 64,
featureProperties : ['scene_id', 'obj_type','direction'],
iterationWeights: [0.1, 0.1, 0.1, 0.1, 0.1, 0.5],
mutateProperty: 'embedding'
}
)
对于此查询,我收到以下错误:
无法调用过程 gds.fastRP.mutate:原因:java.lang.IllegalArgumentException:所有请求的标签均不存在功能属性 ['direction'、'obj_type'、'scene_id']。请求的标签:['图像'、'车道'、'对象']。所有请求的标签上可用的属性:[]
要在确定嵌入时合并所有三个属性
scene_id
、obj_type
和 direction
,所有节点都必须具有所有三个属性。在您的投影中,每个节点仅具有三个属性之一。
一种选择是在本机投影中使用全局配置,为缺少这些属性的节点提供默认值(我选择 0 只是为了说明):
CALL gds.graph.project(
'imgraph1',
['Image', 'Object', 'Lane'],
['CONTAINS', 'IN_LANE'],
{
nodeProperties: {
scene_id: {defaultValue: 0},
obj_type: {defaultValue: 0},
direction: {defaultValue: 0}
}
});
或者您可以将这三个属性合并到投影中的一个新属性中。这是一个简单的示例,其中三个属性中的第一个非空值填充一个新属性
p
:
MATCH (s)-[r]->(t)
WITH gds.graph.project(
'imgraph1',
s,
t,
{
sourceNodeLabels: labels(s),
sourceNodeProperties: s { p: coalesce(s.scene_id, s.obj_type, s.direction)},
targetNodeLabels: labels(t),
targetNodeProperties: t { p: coalesce(t.scene_id, t.obj_type, t.direction)},
relationshipType: type(r)
}
) AS g
RETURN *