Building a Recommender System from Scratch — (1)

A Practical Guide to Creating an Amazon & Flipkart-like Recommendation Engine

Rhydham Gupta
6 min readMay 22, 2023

Personalization is the new formula of success for many companies in today’s business landscape. A significant proportion of ML/AI-based use cases require building an efficient and explainable recommender system and hence there is a very good demand for people who are proficient in building recommendation systems for personalization.

However, most available resources on recommender systems often focus on movie ratings that do not reflect real-world scenarios. How often do you provide ratings of your purchase — very often or never, right? So we need some other metrics to gauge the customer behavior and intent. In this article, we will understand the methodology to build the recommender system from scratch with some real-used metrics.

A good recommender system is built upon multiple building blocks. In any e-commerce application like Amazon, we have two sets of broad recommendations —

  1. Homepage Recommendations (Which is a combination of trending products, past purchases, recommendations based on past purchases, etc.)
  2. Product-Specific Recommendations (When you select a product, there is a list of product recommendations listed as you scroll down the page). If you observe carefully, these recommendations serve as a building block for the final recommendations on the Homepage

So in this series of articles, we will start with understanding the product-specific recommendations. we will come back to the homepage recommendations towards to end.

Some of the most popular and common recommender systems techniques are mentioned below

  • Collaborative Filtering
  • Content-Based Filtering
  • Market Basket Analysis

The real art is defining the analytical problem from different aspects before applying these techniques, let's understand what I mean by analytical problem —

Below are some of the common sections from Amazon and Flipkart that fall under product-specific recommendations:

  1. Customers who bought this item also bought these items (Collaborative Filtering)
  2. Customers who viewed items in your browsing history also viewed/Inspired by your browsing history (Collaborative Filtering)
  3. What other items do customers buy after viewing this item (Collaborative Filtering)
  4. Products related to this item/Similar Items (Content-based filtering)
  5. Featured items you may like/Popular products based on this item (Content-based filtering)
  6. You might be interested in similar categories (Content-based filtering)
  7. Frequently bought together (Market Basket Analysis)

1. Customers who bought this item also bought these items

By analyzing purchase histories, we can identify patterns where customers who bought a particular item also purchased other related items. The basic hypothesis of this section is that many customers have similar purchasing behavior. If there are two customers A and B who have purchased 70% of common items, then there is a high chance that A will like the remaining 30% of items that B has purchased.

Selected Item: Samsung Galaxy M33 5G (Mystique Green, 6GB, 128GB Storage) | 6000mAh Battery | Upto 12GB RAM with RAM Plus | Without Charger

The recommended smartphones are very similar to the selected item with the OnePlus smartphone coming as a surprise. This is one of the biggest advantages of this section that this is driven by similarity in customer purchasing behavior, and because of that, even some unexpected recommendations are likely to do very well.

2. Customers who viewed items in your browsing history also viewed/Inspired by your browsing history

Understanding customer browsing behavior allows us to recommend items based on their interests and preferences. By analyzing patterns in users’ browsing histories, we can suggest relevant products, increasing engagement and conversion rates.

Notice, that based on my recent browsing history, recommended items are also from different categories.

3. What other items do customers buy after viewing this item

Analyzing the purchase sequence of customers who viewed a particular item provides valuable insights into purchase patterns. This is a very interesting section because Amazon believes that what customers viewed previously is a strong indicator of what customers will purchase next.

Selected Item: Samsung Galaxy A54 5G (Awesome Graphite, 8GB, 256GB Storage) | 50 MP No Shake Cam (OIS) | IP67 | Gorilla Glass 5 | Voice Focus | Without Charger

Generally, before buying a smartphone, I often search for other similar smartphones to compare their features and prices. That might be the reason that there are so many smartphones in the recommended items. Isn’t it interesting that travel adapters are the most purchased items after viewing this smartphone?

4. Products related to this item/Similar Items

Utilizing the content and attributes of products, we can create recommendations based on similarity. By analyzing item characteristics such as category, brand, or features, we can suggest related items to customers, enhancing their overall shopping experience.

Selected Item: SAMSUNG Galaxy F13 (Waterfall Blue, 128 GB) (4 GB RAM)

Selected Item: WellManStore LED Temperature Display with Double Wall Insulated Water Bottle Stainless Steel 500 ml Bottle (Pack of 1, Black, Steel)

This section compares the product attributes to get similar items. Interestingly, for the smartphone, the top two similar products are different variants of the same smartphone.

5. Featured items you may like/Popular products based on this item

Incorporating popularity and trends, we can showcase featured items that align with a customer’s preferences. By highlighting popular products related to their past purchases, we can capture their attention and drive sales.

Selected Item: Samsung Galaxy A54 5G (Awesome Graphite, 8GB, 256GB Storage) | 50 MP No Shake Cam (OIS) | IP67 | Gorilla Glass 5 | Voice Focus | Without Charger

Combining similarity in product attributes with popularity.

6. You might be interested in similar category products

By understanding user preferences, we can recommend items from similar categories. Expanding beyond specific items, this approach broadens the scope of recommendations and helps customers discover new and relevant products.

Selected Item: SAMSUNG Galaxy F13 (Waterfall Blue, 128 GB) (4 GB RAM)

This section of recommendation plays smart, Instead of recommending similar items it recommends the associated categories of products based on the selected item. In the above example, when a smartphone is selected, it recommends purchasing mobile skin stickers, wired earphones, and smart glasses.

7. Frequently bought together

Leveraging user purchase history, we can identify products frequently bought together. This association provides valuable insights for cross-selling and enhancing customer satisfaction.

Selected Item: Samsung Galaxy A54 5G (Awesome Graphite, 8GB, 256GB Storage) | 50 MP No Shake Cam (OIS) | IP67 | Gorilla Glass 5 | Voice Focus | Without Charger

This section is about recommending items that are bought together in the same transaction.

In addition to the above strategies, there are several other strategies that can be used to pop up products in your recommendation system:-

  • Trending Items
  • Frequently repurchased items (like grocery items)

This is an introductory article related to a real recommendation engine. In the series of articles, we will go in-depth into each section and explore the methodology to build it from scratch.

--

--

Rhydham Gupta

I am a Data Scientist, I believe that observing and decoding data is an art. Same Data, Different Eyes Different Stories