The previous chapter covered deep learning-based recommender systems and explained how to implement end-to-end neural collaborative filtering. This chapter explores another recent advanced method: graph-based recommendation systems powered by knowledge graphs.
In graph-based recommendation systems, knowledge graph structures represent relationships between users and items. A knowledge graph is the structure of a network of interconnected datasets, enriched with semantics, that is visualized graphically by illustrating the relationship between multiple entities. The graph structure, when visualized, has three primary components; nodes, edges, and labels. The edge of the link defines the relationship between two nodes/entities, where each node can be any object, user, item, place, and so forth. The underlying semantics provide an additional dynamic context to the defined relationships, enabling more complex decision-making.
This chapter uses Neo4j to implement the knowledge graphs. Neo4j is one of the best graph databases in the market today. It is a high-performance graph store with a user-friendly query language that is highly scalable and robust.
The knowledge graphs will fetch similar users for the required recommendations.
Implementation
Before establishing the connection between Neo4j and the notebook, create a new sandbox in Neo4j at https://neo4j.com/sandbox/.
Once the sandbox is created, you must change the URL and the password.
Let’s upload the entities into the Neo4j database.
Next, create a link between the stock codes and title, which are needed to recommend items.
Create a relationship between customers and stocks.
Next, let’s find similarities between users using the relationship created.
The top eight stock codes and product names bought by a particular customer
Recommendations for the same customer and the number of times neighbors bought the same item
- 1.
Get the most similar customers for the given customer.
- 2.
Fetch all the items bought by the nearest neighbors and remove the items the target customer has already bought.
- 3.
From the filtered set of items, count the number of times each item is repeating within the shopping carts of nearest neighbors and then sort that list on the count of repetitions and return in descending order.
Summary
This chapter briefly covered knowledge graphs and how graph-based recommendation engines work. You saw an actual implementation of an end-to-end graph-based recommender system using Neo4j knowledge graphs. The concepts used are very new and advanced and have become popular recently. Big players like Netflix and Amazon are shifting to graph-based systems for their recommendations; hence, the approach is very relevant and must-know.