Neo4j图库算法

Neo4j图库算法包含以下6种链路预测算法:

Neo4j图库算法_第1张图片

下面创建一个图谱,实践各个算法。

UNWIND [["A", "C"], ["A", "B"], ["B", "D"],
        ["B", "C"], ["B", "E"], ["C", "D"]] AS pair
MERGE (n1:Node {name: pair[0]})
MERGE (n2:Node {name: pair[1]})
MERGE (n1)-[:FRIENDS]-(n2)

Neo4j图库算法_第2张图片

  • 共同邻居算法
    match (a:Node {name:'A'})	
    match (d:Node {name:'D'}) 
    return algo.linkprediction.commonNeighbors(a,d)

    可以看到 A、D的共同邻居有B、C。

    Neo4j图库算法_第3张图片

加入参数进行计算

with {direction:"BOTH", relationshipQuery:"FRIENDS"} as config 
match (a:Node {name:'A'})	
match (d:Node {name:'D'}) 
return algo.linkprediction.commonNeighbors(a,d,config)

 Neo4j图库算法_第4张图片

  • Adamic Adar算法
    match (a:Node {name:"A"})	
    match (d:Node {name:'D'}) 
    return algo.linkprediction.adamicAdar(a,d) as score

     Neo4j图库算法_第5张图片

  • 优先连接算法(Preferential Attachment)
    match (a:Node {name:"A"})	
    match (d:Node {name:'D'}) 
    return algo.linkprediction.preferentialAttachment(a,d) as score

    Neo4j图库算法_第6张图片

  • 资源分配算法(ResourceAllocation)

    match (a:Node {name:"A"})	
    match (d:Node {name:'D'}) 
    return algo.linkprediction.resourceAllocation(a,d) as score

    Neo4j图库算法_第7张图片

  • 共同社区算法(Same Community)

    match (a:Node {name:"A"})	
    match (d:Node {name:'D'}) 
    return algo.linkprediction.sameCommunity(a,d) as score

    Neo4j图库算法_第8张图片

  • 总邻居算法(Total Neighbors)

    match (a:Node {name:"A"})	
    match (d:Node {name:'D'}) 
    return algo.linkprediction.totalNeighbors(a,d) as score

    Neo4j图库算法_第9张图片

 

 

你可能感兴趣的:(知识图谱,AI,Neo4j,图算法)