In this notebook you will learn how to make recommendations using Neo4j.
Execute the code to import the libraries (remember to unset Reset all runtimes before running):
from py2neo import Graph
import pandas as pd
import matplotlib
import matplotlib.pyplot as plt
plt.style.use('fivethirtyeight')
pd.set_option('display.float_format', lambda x: '%.3f' % x)
pd.set_option('display.max_colwidth', 100)
Update the cell below to use the IP Address, Bolt Port, and Password, as you did previously.
# Change the line of code below to use the Bolt URL, and Password of your Neo4j database instance.
# graph = Graph("<Bolt URL>", auth=("neo4j", "<Password>"))
graph = Graph("bolt://localhost:7687", auth=("neo4j", "letmein"))
query = """
MATCH (author:Author {name: $authorName})<-[:AUTHOR]-(article)-[:AUTHOR]->(coauthor),
(coauthor)<-[:AUTHOR]-()-[:AUTHOR]->(coc)
WHERE not((coc)<-[:AUTHOR]-()-[:AUTHOR]->(author)) AND coc <> author
RETURN coc.name AS coauthor, count(*) AS collaborations
ORDER BY collaborations DESC
LIMIT 20
"""
params = {"authorName": "Brian Fitzgerald", "searchTerm": "open source"}
graph.run(query, params).to_data_frame()
coauthor | collaborations | |
---|---|---|
0 | Holger Giese | 5 |
1 | Grace A. Lewis | 4 |
2 | Robert C. Seacord | 4 |
3 | Gabriel A. Moreno | 4 |
4 | Kurt C. Wallnau | 4 |
5 | Chris Jensen | 4 |
6 | Judith A. Stafford | 4 |
7 | Thomas D. LaToza | 3 |
8 | Klaus Pohl | 3 |
9 | Gerald Bortis | 3 |
10 | Ivar Jacobson | 3 |
11 | Nicolás López | 3 |
12 | Salah Bendifallah | 2 |
13 | Thuan Q. Pham | 2 |
14 | Gregor Engels | 2 |
15 | Pankaj K. Garg | 2 |
16 | Gary Thunquest | 2 |
17 | Pavel Dmitriev | 2 |
18 | Peiwei Mi | 2 |
19 | Neil Smith | 2 |
query = """
MATCH (author:Author {name: $authorName})<-[:AUTHOR]-(article)-[:AUTHOR]->(coauthor),
(coauthor)<-[:AUTHOR]-()-[:AUTHOR]->(coc)
WHERE not((coc)<-[:AUTHOR]-()-[:AUTHOR]->(author)) AND coc <> author
WITH coc, count(*) AS collaborations
WHERE collaborations > 3
RETURN count(*)
"""
graph.run(query, params).to_data_frame()
count(*) | |
---|---|
0 | 7 |