What is a Recommendation System?
Recommendation engines are a class of algorithms and models created to suggest items or content to users based on their preferences. These algorithms utilize user behavior patterns to identify and present the most likely items of interest to the user. An early and widely embraced manifestation of recommendation engines is the “people also bought” algorithm, developed through a market basket analysis approach.
In contemporary scenarios, recommendation engines exhibit a diverse range of complexities as organizations employ various methodologies for their design and deployment. For instance, some recommendation engines are designed to evolve their understanding of user preferences over time, with the goal of continuously improving recommendations. In contrast, others may utilize “collaborative filtering,” drawing on aggregated behavioral patterns and preferences from a larger user base to discern and provide the most relevant products to specific users.
The choice of an appropriate approach for constructing recommendation engines depends on organizational factors, including data availability, industry context, user demographics, and desired functionalities. Implementing a recommendation engine doesn’t have to be a singular, burdensome project; instead, it can be modularized into distinct phases, starting with a specific use case and corresponding recommender systems approach, and evolving over time.
A recommendation system is a subclass of Information filtering Systems that seeks to predict the rating or the preference a user might give to an item. In simple words, it is an algorithm that suggests relevant items to users. Eg: In the case of Netflix which movie to watch, In the case of e-commerce which product to buy, or In the case of kindle which book to read, etc.
Here’s a brief overview of how you can create a simple recommendation engine:
- Define the problem: Before you start building the recommendation engine, it’s important to understand what you want to achieve. You need to define the problem you’re trying to solve and what kind of recommendations you want to generate.
- Choose a recommendation algorithm: There are different types of recommendation algorithms, such as content-based filtering, collaborative filtering, and hybrid filtering. You need to choose the one that best suits your needs.
- Gather data: You need to gather data about the items you want to recommend and the users who will be using the recommendation engine.
- Preprocess the data: Once you have the data, you need to preprocess it to make it suitable for the recommendation algorithm you’ve chosen.
- Implement the recommendation algorithm: You need to implement the recommendation algorithm using a programming language.
- Test the recommendation engine: Finally, you need to test the recommendation engine to make sure it’s generating accurate recommendations.
Let’s build a simple project
This project recommends games based on your friends preferences. The assumption is that if you have friends who like similar categories (ie: genres) as you, those games will be recommended to you. It also has a function to promote the least popular games (this is to boost them).
Althoug you can get all the categories from the following list, I wish to keep it simple for this example. I am not specifying any game titles here although this can be replaced very easily.
Players vs Game categories
Who like what category?
Player 1 | Player 2 | Player 3 | Player 4 | Player 5 | Totals | |
First person shooter | x | x | x | 3 | ||
Racing | x | x | x | 3 | ||
Puzzle | x | x | x | x | 4 | |
Sports | x | x | 2 | |||
RPG | 0 | |||||
Totals | 3 | 3 | 2 | 2 | 2 |
Games vs categories
What game comes under what category?
Game 1 | Game 2 | Game 3 | Game 4 | Game 5 | Totals | |
First person shooter | x | x | 2 | |||
Racing | x | x | x | 3 | ||
Puzzle | x | 1 | ||||
Sports | x | 1 | ||||
RPG | x | 1 | ||||
Totals | 2 | 1 | 2 | 1 | 2 |
Player friendship matrix
Who is friends with who?
Player 1 | Player 2 | Player 3 | Player 4 | Player 5 | Totals | |
Player 1 | x | x | x | 3 | ||
Player 2 | x | x | x | 3 | ||
Player 3 | x | x | x | 3 | ||
Player 4 | x | x | 2 | |||
Player 5 | x | x | x | 3 | ||
Totals | 3 | 3 | 3 | 2 | 3 |
Questions we need to ask:
- Which game category is liked by which users
- Which game categories are liked least → RPG
- Who likes racing → user 2, user 3, user 5
- From #3 what other categories do they like most → Puzzle
- Propose the results from #4 to user who did not select those → user 5 to puzzle
- Propose results from #2 to random users
We can approach this project using 2 fronts. The traditional “tabular, relational database” approach looks simple but the queries become complicated. A graph database based approach gives much more flexibility in queries. Neo4J is one of the pioneers in this field. I am using the free tire for this project.
Using “relational database” system
Models/entities
- players [id, name, email]
- games [id, title, publisher, version, year]
- categories [id, title]
- game_categories [game_id, category_id]
- player_categories [player_id, category_id]
- player_friends [player_id, friend_id]
SQL
Using “graph database” system
Sample code
I am sharing a GitHub repo, a work in progress. Please pay attention to the README.
Here are some resources that can help you get started:
- A very simple explanation with 3 hops: https://www.graphable.ai/blog/building-recommendation-engines/
- This Medium article provides a step-by-step guide to building a simple recommendation engine using JavaScript and Neo4j.
- This Dev.to article explains how to build a content-based recommendation engine in JavaScript.
- This Toptal article provides an algorithm tutorial for building a recommendation engine with CoffeeScript
- https://towardsdatascience.com/how-to-build-a-recommendation-engine-quick-and-simple-aec8c71a823e
- https://www.geeksforgeeks.org/building-recommendation-engines-using-pandas/
- This articles compass content based filtering, User based & item based collaborative filtering, and evaluation metrics https://www.analyticsvidhya.com/blog/2021/07/recommendation-system-understanding-the-basic-concepts/
- Using Alternating Least Squares (ALS) algorithm: https://medium.com/@hardefarogonondo/from-concept-to-code-crafting-a-recommendation-engine-from-zero-1e7271ed1079
Graph Database
- BEST: Explores graph based recommendation engine: https://www.graphable.ai/blog/what-is-a-recommendation-engine/
- Good explanation of Graph database: https://www.graphable.ai/blog/what-is-a-graph-database/
- Complete overview of Neo4J: https://www.graphable.ai/software/what-is-neo4j-graph-database/
- Neo4J video series: https://www.youtube.com/watch?v=zNUzkvptw8E&list=PLqfPEK2RTgChcOZ6qHgSfwiBPCz2Bzdjh
- What is a Graph Database? https://youtu.be/dGHSKpx4Xjs
- Designing a Neo4j Database Part 1: https://youtu.be/paRhziilw0A
- Part 2: https://youtu.be/UlusC7CZSFE?si=zz8S5DEFGFExhX8X
- Intro to Graph Databases Episode #5 – Cypher, the Graph Query Language: https://youtu.be/l76udM3wB4U
- https://neo4j.com/docs/getting-started/appendix/tutorials/guide-cypher-basics/
- BEST: Node.js With Neo4j – Freestyle Coding [2]: https://youtu.be/snjnJCZhXUM
- BEST: https://neo4j.com/docs/getting-started/appendix/tutorials/guide-build-a-recommendation-engine/