First of all, let's export the data from Neo4j to a pandas DataFrame using the Neo4j Python driver (similar to the method used in Chapter 8, Using Graph-Based Features in Machine Learning):
import pandas as pd
from neo4j import GraphDatabase
driver = GraphDatabase.driver("bolt://localhost:7687", auth=("neo4j", "<YOUR_PASSWORD>"))
cypher = """
MATCH (u)
MATCH (v)
WHERE u.id < v.id // exclude u = v
AND NOT ( (u)-[:KNOWS_T2]-(v) )
WITH u, v, gds.alpha.linkprediction.adamicAdar(
u, v, {
relationshipQuery: "KNOWS_T1",
direction: "BOTH"
}
) as score
RETURN u.id as u_id,
v.id as v_id,
score,
EXISTS( (u)-[:KNOWS_T1]-(v) ) as label
"""
with driver.session() as session:
rec = session.run(cypher)
df = pd.DataFrame.from_records(rec.data())
Remember to update the preceding code...