Title: Amazon Product Recommendation Systems - PyImageSearch

URL Source: https://pyimagesearch.com/2023/08/14/amazon-product-recommendation-systems/

Published Time: 2023-08-14T13:00:00+00:00

Markdown Content:
* * *

**Table of Contents**
---------------------

*   [Amazon Product Recommendation Systems](#h2BPTitle)

*   [Related-Product Recommendations](#h3RPR)
    [](#h3RPR)*   [](#h3RPR)[Product Graph](#h4ProductGraph)
    
    *   [Product Relationships](#h5Relationships)
    *   [Selection Bias and Cold Start](#h5Bias)
    *   [Graph Construction](#h5Construction)
    
    *   [Product Embedding Generation: Forward Pass](#h4Forward)
    
    *   [Algorithm](#h5Algorithm)
    
    *   [Loss Function and Training](#h4Loss)
*   [Repeat Purchase Recommendations](#h3RepeatPurchase)

*   [Repeat Customer Probability Model](#h4RepeatCustomer)
*   [Aggregate Time Distribution Model](#h4ATDM)
*   [Poisson-Gamma Model](#h4PGM)

*   [Query-Attribute Search Recommendation](#h3QASR)

*   [Query Intent Classification](#h4QIC)
*   [Explicit Attribute Parsing](#h4Explicit)
*   [Implicit Attribute Recommendation](#h4Implicit)

*   [Summary](#h2Summary)

*   [Citation Information](#h3Citation)

* * *

In this tutorial, you will learn about Amazon product recommendation systems.

[![Image 1](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20603%20500'%3E%3C/svg%3E)](https://pyimagesearch.com/wp-content/uploads/2023/08/amazon-rec-systems-featured.png)

Over the past decade, Amazon has become the first place to look for any product we want. With hundreds of millions of items in its catalog, it has made shopping easy for customers by putting the items they are likely to purchase in front. Everyone who comes to amazon.com sees a different homepage personalized according to his interests and purchases.

Behind the scenes are state-of-the-art recommendation engines that suggest a few products (from a vast catalog) based on your interests, current context, past behavior, and purchases. For example, the app might suggest iPhone covers if you recently purchased an iPhone or are currently looking to purchase one. Another example would be recommending products (e.g., toothpaste, diapers, etc.) based on your purchasing history to promote repeat purchasing.

This lesson will cover several aspects of Amazon recommendations (e.g., related-product recommendations, repeat purchase recommendations, and search recommendations) and how they work behind the scenes.

This lesson is the 1st in a 3-part series on **Deep Dive into Popular Recommendation Engines 102**:

1.  [**_Amazon Product Recommendation Systems_**](https://pyimg.co/m8ps5) **(this tutorial)**
2.  _YouTube Video Recommendation Systems_
3.  _Spotify Music Recommendation Systems_

**To learn how the Amazon recommender systems work,** **_just keep reading._**

* * *

[**Amazon Product Recommendation Systems**](#TOCh2BPTitle)
----------------------------------------------------------

In this lesson, we will discuss Amazon’s three major recommendation systems: related product, repeat purchase, and query-attribute search recommendations.

* * *

### [**Related-Product Recommendations**](#TOCh3RPR)

Recommending related products (**Figure 1**) to customers is important as it helps them find the right products easily on an e-commerce platform and, at the same time, helps them discover new products, thereby delivering them a great shopping experience. The goal of the related-product recommendation is to recommend top-![Image 2: k](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%209%2011'%3E%3C/svg%3E) products that are likely to be bought together with the query product.

[![Image 3](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20700%20343'%3E%3C/svg%3E)](https://lh6.googleusercontent.com/KNy7JBkxg6EpF7XNUCsU8ZjMO09YW6flc9tD0W0XpBYeUHeXqoF2g2MErBidhRq4AesiZQhhc7ZGsHk9Tsu4tb0D1mxuBIPSA3Wo7G-Vtld-jSqWlHUTkDl-_5rq4w20ZagqSVDOPrtIkvDE1u14Wbc)

**Figure 1:** Related-product recommendations at Amazon (source: [LaptrinhX](https://laptrinhx.com/12-ways-amazon-optimizes-product-pages-to-drive-billions-45692295/)).

* * *

#### [**Product Graph**](#TOCh4ProductGraph)

* * *

##### [**Product Relationships**](#TOCh5Relationships)

To formulate the problem statement, let’s assume ![Image 4: a](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%209%207'%3E%3C/svg%3E), ![Image 5: b](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%207%2011'%3E%3C/svg%3E), and ![Image 6: c](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%207%207'%3E%3C/svg%3E) be any three products and ![Image 7: R_\text{cp}](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2024%2016'%3E%3C/svg%3E), ![Image 8: R_\text{cv}](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2023%2014'%3E%3C/svg%3E), and ![Image 9: R_\text{like}](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2030%2015'%3E%3C/svg%3E) be three binary relationships where:

**Figure 2** illustrates a product graph where green and blue edges represent co-purchase and co-view edges. AC refers to the adapter, AP refers to AirPods, P refers to iPhone, and PC refers to the phone case. Phone case PC is co-viewed and similar to other phone cases PC1, PC2, and PC3. Note that co-purchase edges are directional as ![Image 10: aR_\text{cp}b \nRightarrow bR_\text{cp}a](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20107%2016'%3E%3C/svg%3E). This is called the product asymmetry challenge in a related-product recommendation.

[![Image 11](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20568%20500'%3E%3C/svg%3E)](https://lh6.googleusercontent.com/C8ADZbsG2SXv5uZXZ9qUm-j1P1hzQ33XwSypWe7_hIzU6PuZua3_MpLsX2vI8B9FVNNX3SwXszfsVjG6B_XrbBZ4G_-DWUtuiVNde-Ku57D2INsgwoWDa4TNJXq5fj5CdY3DEnseMXSqVCX3yKK3fNA)

**Figure 2:** Product graph representing co-purchase and co-view relationships between products (source: [Amazon Science](https://assets.amazon.science/d6/56/d03a00d14fd39c3486614e611e51/recommending-related-products-using-graph-neural-networks-in-directed-graphs.pdf)).

* * *

##### [**Selection Bias and Cold Start**](#TOCh5Bias)

Along with capturing the asymmetry in the co-purchase relationship, related-product recommendations suffer from the challenge of selection bias, which is inherent to historical purchase data due to product availability, price, etc.

For example, the first customer was presented with phone cases PC and PC1 due to the unavailability of PC2 in their location. At the same time, a second customer was presented with only PC and PC2 because PC1 was out of stock. However, both end up purchasing PC, but that doesn’t mean that PC is a better choice. This creates a selection bias problem.

To mitigate this, we also need to capture second-order relationships of the following types:

*   ![Image 12: aR_\text{cp}b \land bR_\text{cv}c \implies aR_\text{cp}c](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20182%2016'%3E%3C/svg%3E)
*   ![Image 13: aR_\text{cv}b \land bR_\text{cp}c \implies aR_\text{cp}c](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20182%2016'%3E%3C/svg%3E)

Another challenge in related-product recommendations is the cold start problem, where we might also need to suggest newly launched products. Assume ![Image 14: c](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%207%207'%3E%3C/svg%3E) is a new product, and ![Image 15: a](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%209%207'%3E%3C/svg%3E) and ![Image 16: b](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%207%2011'%3E%3C/svg%3E) are existing products. To address this, we need to uncover relationships of the following type:

* * *

##### [**Graph Construction**](#TOCh5Construction)

Amazon uses graph neural networks (GNNs) to model these relationships between products by learning their respective product embeddings (**Figure 3**). Before describing the approach, let’s look at how the product graph is constructed.

[![Image 17](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20700%20394'%3E%3C/svg%3E)](https://lh4.googleusercontent.com/tZPIALmFocZs81iHuPtSUZ-BHpZq1cMbGgghNptHlSaCRcfDd8v39o06CXfVh2oVVAes2Q0Kj8kXmtG14eZvzm03-YMsd0c3ghlTXREIeV2XtWvRjM9dRPjZw6mmdf-DDAEweCxGI6aC7dKt2dBz0_E)

**Figure 3:** Using GNNs for related-product recommendations (source: [Amazon Science](https://www.amazon.science/blog/using-graph-neural-networks-to-recommend-related-products)).

The product graph ![Image 18: G = (P, \{ E_\text{cp} \cup R_\text{cv} \}](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20143%2019'%3E%3C/svg%3E) consists of a set of vertices ![Image 19: P](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2013%2011'%3E%3C/svg%3E) that represents products. ![Image 20: E_\text{cp}](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2024%2016'%3E%3C/svg%3E) represents the set of co-purchase edges (i.e., ![Image 21: E_\text{cp} = \{ (u,v) | \forall u,v \in P \land uR_\text{cp}v \}](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20233%2019'%3E%3C/svg%3E)).

However, ![Image 22: E_\text{cp}](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2024%2016'%3E%3C/svg%3E) is prone to selection bias and might miss relationships of type ![Image 23: aR_\text{cp}b \land bR_\text{cv}c \implies aR_\text{cp}c](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20182%2016'%3E%3C/svg%3E) and ![Image 24: aR_\text{cv}b \land bR_\text{cp}c \implies aR_\text{cp}c](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20182%2016'%3E%3C/svg%3E).

To address this, we also include ![Image 25: E_\text{cv}](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2023%2014'%3E%3C/svg%3E) which represents the set of co-viewed edges (i.e., ![Image 26: E_\text{cv} = \{ (u,v) | \forall u,v \in P \land uR_\text{cv}v \}](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20232%2018'%3E%3C/svg%3E)).

With this, graph ![Image 27: G](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2013%2011'%3E%3C/svg%3E) now handles asymmetry and selection bias by containing the following product relationships:

*   Asymmetry: ![Image 28: aR_\text{cp}b \nRightarrow bR_\text{cp}a](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20107%2016'%3E%3C/svg%3E)
*   Selection bias: ![Image 29: aR_\text{cp}b \land bR_\text{cv}c \implies aR_\text{cp}c](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20182%2016'%3E%3C/svg%3E)
*   Selection bias: ![Image 30: aR_\text{cv}b \land bR_\text{cp}c \implies aR_\text{cp}c](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20182%2016'%3E%3C/svg%3E)

**Figure 4** illustrates what a product graph looks like.

[![Image 31](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20613%20500'%3E%3C/svg%3E)](https://lh5.googleusercontent.com/sL15yb2oNdFTAy7SajYzG-u7ScXbCdGs_rbuyKiVcyiu0v6vzejZKpOSYMy3aV4L2YpBcudgZ2J6_oipRMjU0rJDfPTIX3DUft0QTT-9SPEhvOK47kutsqrwpRi6-dZ2quYUOavOEYlI6e3b9grzNnw)

**Figure 4:** Product graph representing co-purchase (uni-directed) and co-view (bi-directed) relationships between products (source: [Amazon Science](https://www.amazon.science/blog/using-graph-neural-networks-to-recommend-related-products)).

* * *

#### [**Product Embedding Generation: Forward Pass**](#TOCh4Forward)

* * *

##### [**Algorithm**](#TOCh5Algorithm)

The GNN approach learns two embeddings for each product: source and target. Source and target embeddings are used when the product is a query and recommended item, respectively.

**Algorithm 1** explains the procedure for generating these embeddings. Let ![Image 32: (h^s_u)^l](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2031%2018'%3E%3C/svg%3E) and ![Image 33: (h^t_u)^l](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2031%2018'%3E%3C/svg%3E) denote the source and target embedding for product ![Image 34: u](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%209%207'%3E%3C/svg%3E) at the ![Image 35: l^\text{th}](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2017%2014'%3E%3C/svg%3E) step in the algorithm. These embeddings are initialized with their respective product input features.

[![Image 36](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20700%20384'%3E%3C/svg%3E)](https://lh6.googleusercontent.com/Ez17GmFsKuAo919NNPOCDB5fteGJM9-xC9kqVAkwHqZ11yqW1TfN5IxgoRJAjjRyM0GeuIMC7Bg-zR-mDWHOK078ErDfOLbNgyzEH1Fxr9Kat0weAW52BxmQkTXB-bgJxVhIf7tdZGDhzkLO9RpL07U)

**Algorithm 1:** Generating product source and graph embeddings using the GNN approach (source: [Amazon Science](https://assets.amazon.science/d6/56/d03a00d14fd39c3486614e611e51/recommending-related-products-using-graph-neural-networks-in-directed-graphs.pdf)).

First, the algorithm extracts the co-purchase and co-view neighbors for each product ![Image 37: u](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%209%207'%3E%3C/svg%3E). The source embedding of product ![Image 38: u](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%209%207'%3E%3C/svg%3E) at the ![Image 39: l^\text{th}](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2017%2014'%3E%3C/svg%3E) step (i.e., ![Image 40: (h^s_u)^l](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2031%2018'%3E%3C/svg%3E)) is computed as a linear combination of two non-linear terms (**Line 4** of **Algorithm 1**).

The first term is the non-linear aggregation of target representations of its co-purchase neighbors at the ![Image 41: (l-1)^\text{th}](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2057%2018'%3E%3C/svg%3E) step. Similarly, the second term is the non-linear aggregation of target representations of its co-viewed neighbors at the ![Image 42: (l-1)^\text{th}](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2057%2018'%3E%3C/svg%3E) step. In other words,

![Image 43: (h^s_u)^l \leftarrow \text{ReLU} \left (\sum_{(u,v) \in E_\text{cp}} (h^t_v)^{l-1} W^l \right) + \text{ReLU} \left (\sum_{(u,v) \in E_\text{cv}} (h^t_v)^{l-1} W^l \right),](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20495%2031'%3E%3C/svg%3E)

where ![Image 44: \text{ReLU}](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2041%2013'%3E%3C/svg%3E) is ReLU activation, and ![Image 45: W^l](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2021%2014'%3E%3C/svg%3E) are weights of a fully connected layer at step ![Image 46: l](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%205%2011'%3E%3C/svg%3E).

We do similar things for generating target representation ![Image 47: (h^t_u)^l](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2031%2018'%3E%3C/svg%3E) of each product ![Image 48: u](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%209%207'%3E%3C/svg%3E) (**Line 5** of **Algorithm 1**). The source and target embeddings are then normalized (**Lines 7 and 8** of **Algorithm 1**) to the unit norm, and this process is repeated till ![Image 49: L](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2011%2011'%3E%3C/svg%3E) steps to generate the final source and target embeddings ![Image 50: \theta^s_u](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2015%2015'%3E%3C/svg%3E) and ![Image 51: \theta^t_u](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2015%2017'%3E%3C/svg%3E) for each product ![Image 52: u](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%209%207'%3E%3C/svg%3E).

##### [**Related-Product Recommendation**](#TOCh5Related)

Given a query product ![Image 53: q](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%208%2010'%3E%3C/svg%3E) and its source embedding ![Image 54: \theta^s_q](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2014%2017'%3E%3C/svg%3E), we perform a nearest neighbor lookup in target embedding space and recommend top-![Image 55: k](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%209%2011'%3E%3C/svg%3E) products. The relevance or utility score ![Image 56: \text{relevance}(q,v)](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2099%2018'%3E%3C/svg%3E) of a candidate product ![Image 57: v](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%208%207'%3E%3C/svg%3E) with respect to query product is calculated as:

![Image 58: \text{relevance}(q, v) \ = \ (\theta^s_q)^T(\theta^t_v)](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20195%2020'%3E%3C/svg%3E)

Note that ![Image 59: \text{relevance}(q, v) \neq \text{relevance}(v, q)](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20222%2018'%3E%3C/svg%3E), which helps us capture the asymmetry in co-purchase relationships.

Given a cold-start product ![Image 60: c](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%207%207'%3E%3C/svg%3E), we perform a neighbor lookup to identify ![Image 61: k](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%209%2011'%3E%3C/svg%3E) similar products ![Image 62: \{c_1, c_2, \dots, c_k\}](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20100%2017'%3E%3C/svg%3E) in the input product feature space. Then we augment the product graph with new edges ![Image 63: \{(c, c_1), (c, c_2), \dots, (c, c_k)\}](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20181%2018'%3E%3C/svg%3E) and pass the sub-graph corresponding to product ![Image 64: c](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%207%207'%3E%3C/svg%3E) to **Algorithm 1** to generate its source and target embeddings. These embeddings are then used in the same way to compute the utility score.

* * *

#### [**Loss Function and Training**](#TOCh4Loss)

To learn the fully connected layer parameters ![Image 65: W](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2018%2011'%3E%3C/svg%3E), we use an asymmetric loss function, as shown in **Figure 5**.

[![Image 66](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20700%20351'%3E%3C/svg%3E)](https://lh4.googleusercontent.com/3sNePrQU_cMOoixdAfZiK9sT_hMJDDHSZbZG_dBSj-_oKrbVRbDQNKcXr-zuQrbqtrU4wufMt1vXd8GdV_--Mw190Bkh3IWFDLDbLpexeRk-rr3tsDpl90P_pxBbRIKJ91eX3NY1uwk7WfCHKKbrhyg)

**Figure 5:** Loss function used for training GNN for related-product recommendation (source: [Amazon Science](https://assets.amazon.science/d6/56/d03a00d14fd39c3486614e611e51/recommending-related-products-using-graph-neural-networks-in-directed-graphs.pdf)).

The loss function contains three terms:

* * *

### [**Repeat Purchase Recommendations**](#TOCh3RepeatPurchase)

Repeat purchasing (i.e., a customer purchasing the same product multiple times) is an important phenomenon in e-commerce platforms (**Figure 6**). Modeling repeat purchases helps businesses increase their product click-through rate and makes the shopping experience easy for customers.

[![Image 67](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20700%20285'%3E%3C/svg%3E)](https://lh6.googleusercontent.com/v69_AJ0EAaxTa35Eowsa4E_5ve-z2xoX0K3f7-_u_ed1VmE3ALOCoiaFli7fZ_hgJJIdBT2Voh8LAKY-w8kdFnVIs1usBuLOSbYwe4bfgXvHYGZF0aJ55BHNjpFRtJLv1ObBQGYrFPLmDiEjiie3aU8)

**Figure 6:** Buy-it-again or repeat purchase recommendations at Amazon (source: [Conversion Sciences](https://conversionsciences.com/blog/10-retail-conversion-lessons-from-amazon-com/)).

Repeat purchase recommendations estimate the probability of a customer purchasing a product again as a function of time from their last purchase. In other words, given a customer ![Image 68: C](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2013%2011'%3E%3C/svg%3E) has already purchased a product ![Image 69: A_i](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2016%2014'%3E%3C/svg%3E) ![Image 70: k](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%209%2011'%3E%3C/svg%3E)\-times with time intervals ![Image 71: t_1, t_2, \dots, t_k](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2081%2014'%3E%3C/svg%3E), we want to estimate the purchase probability density:

![Image 72: P_{A_i}(t_{k+1} = t | t_1, t_2, \dots, t_k)](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20178%2019'%3E%3C/svg%3E)

In the above equation, we assume that the product purchases are independent of each other, and the equation can be decomposed into two components:

![Image 73: P_{A_i}(t_{k+1} = t | t_1, t_2, \dots, t_k) \approx Q(A_i) \times R_{A_i}(t_{k+1} = t | t_1, t_2, \dots, t_k, A_i=1),](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20502%2019'%3E%3C/svg%3E)

where ![Image 74: Q(A_i)](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2041%2018'%3E%3C/svg%3E) is the repeat purchase probability of a customer buying a product a ![Image 75: (k + 1)^\text{th}](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2060%2018'%3E%3C/svg%3E) time given that they have bought it ![Image 76: k](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%209%2011'%3E%3C/svg%3E) times. ![Image 77: R_{A_i}](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2025%2016'%3E%3C/svg%3E) is the distribution of ![Image 78: t_{k+1}](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2026%2015'%3E%3C/svg%3E), conditioned on the customer repurchasing that product; indicated by ![Image 79: A_i = 1](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2046%2015'%3E%3C/svg%3E).

This lesson will discuss three frameworks Amazon uses to model repeat purchases.

* * *

#### [**Repeat Customer Probability Model**](#TOCh4RepeatCustomer)

This framework is time-independent and is based on a frequency-based probabilistic model that computes the repeat customer probability ![Image 80: \text{RCP}(A_i)](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2062%2018'%3E%3C/svg%3E) for each product ![Image 81: A_i](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2016%2014'%3E%3C/svg%3E) by using aggregate repeat purchase statistics of products by customers. In other words, it assumes that ![Image 82: R_{A_i} = \text{constant}](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20108%2016'%3E%3C/svg%3E) and ![Image 83: P_{A_i}(t_{k+1} = t | t_1, t_2, \dots, t_k) \approx Q(A_i) \approx \text{RCP}(A_i)](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20328%2019'%3E%3C/svg%3E).

![Image 84: \text{RCP}(A_i) \ = \ \displaystyle\frac{\text{\#s of customers who bought product } A_i \text{ more than once}}{\text{\#s of customers who bought product } A_i \text{ at least once}}](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20501%2040'%3E%3C/svg%3E)

To ensure good quality of repeat product recommendations, we only recommend products for which ![Image 85: \text{RCP}(A_i) > r_\text{threshold}](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20142%2018'%3E%3C/svg%3E), where ![Image 86: r_\text{threshold}](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2056%2011'%3E%3C/svg%3E) is an operating threshold.

* * *

#### [**Aggregate Time Distribution Model**](#TOCh4ATDM)

Amazon analysis shows that most customers have only a few repeat purchases for a specific product (i.e., ![Image 87: \text{RCP}(A_i)](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2062%2018'%3E%3C/svg%3E) is low). But there are many products for which Amazon has many customers making repeat purchases (i.e., ![Image 88: \text{RCP}(A_i)](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2062%2018'%3E%3C/svg%3E) is high). Hence repeat purchases often depend on a customer’s purchase behavior.

Aggregate time distribution (ATD) model is a time-based model that assumes that product purchase density is only a function of past purchase behavior ![Image 89: R_{A_i}](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2025%2016'%3E%3C/svg%3E). In other words, ![Image 90: Q_{A_i} = \text{constant}](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20108%2016'%3E%3C/svg%3E) and ![Image 91: P_{A_i}(t_{k+1} = t | t_1, t_2, \dots, t_k) \approx R_{A_i}(t_{k+1} = t | t_1, t_2, \dots, t_k, A_i=1)](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20435%2019'%3E%3C/svg%3E).

Amazon uses a log-normal distribution for defining ![Image 92: R_{A_i}](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2025%2016'%3E%3C/svg%3E):

![Image 93: R_{A_i}(t) = \mathcal{N}(\ln(t); \mu_i, \sigma_i),](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20174%2019'%3E%3C/svg%3E)

where ![Image 94: \mu_i](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2014%2010'%3E%3C/svg%3E) and ![Image 95: \sigma_i](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2013%2010'%3E%3C/svg%3E) are the mean and variance of the Gaussian distribution.

**Figure 7** illustrates the distribution of repeat purchase time intervals (![Image 96: t](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%206%2010'%3E%3C/svg%3E)) and log repeat purchase time intervals (![Image 97: \log(t)](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2038%2018'%3E%3C/svg%3E)) of a random consumable product across all its repeat purchasing customers.

[![Image 98](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20700%20263'%3E%3C/svg%3E)](https://lh3.googleusercontent.com/jKsdW6LSmF9c4duTnMg1GHcpDf0GWVUG30eIKPDUnaI_CgDzWD_-CNm3w1NNimasM7CPa_gt4MOatW-iqeUVkyO7iMxnhOrQC-dVPle11Mm7m9tUmo7IgxiIFts1rmbpTFGTUvcNedaHyIx9ZEFgygg)

**Figure 7:** Distribution of repeat purchase time intervals (_t_) and log repeat purchase time intervals (log(_t_)) of a random consumable product across all its repeat purchasing customers (source: [Amazon Science](https://assets.amazon.science/40/e5/89556a6341eaa3d7dacc074ff24d/buy-it-again-modeling-repeat-purchase-recommendations.pdf)).

Note that only the products having ![Image 99: \text{RCP}(A_i) > r_\text{threshold}](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20142%2018'%3E%3C/svg%3E) are deemed repeat purchasable and vice versa. Finally, recommendations are generated by considering all the repeat purchasable products previously bought by customers and ranking them in the descending order of their estimated probability density ![Image 100: R_{A_i} (t)](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2043%2019'%3E%3C/svg%3E) at a given time ![Image 101: t](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%206%2010'%3E%3C/svg%3E).

* * *

#### [**Poisson-Gamma Model**](#TOCh4PGM)

Poisson-gamma (PG) model is one of the most seminal works in modeling customer repeat purchases. It assumes the following two assumptions:

[![Image 102](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%200%200'%3E%3C/svg%3E)](https://lh5.googleusercontent.com/_cDKH1arGQsOUrkpVLUg8_P5_35CEeg0f9ZFtJ_OTbwaOpAQqIwbCVHfcenQYrwKocFqr-epGVoydCh3bNJj9Ni4AdO8v-oeikRfPv-N0OYg32IbglbUAaIChfdY0PV11nFGwQ_qyY8qHlZ7pYBgnmA)

**Figure 8:** Poisson Distribution (source: [Brilliant](https://brilliant.org/wiki/poisson-distribution/)).

The parameters ![Image 103: \alpha](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2010%207'%3E%3C/svg%3E) and ![Image 104: \beta](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2010%2014'%3E%3C/svg%3E) of the gamma distribution can be estimated using maximum likelihood estimation over the purchase rates of repeat customers. After this, the purchase rate ![Image 105: \lambda_{A_i, C}](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2035%2016'%3E%3C/svg%3E) for a customer ![Image 106: C](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2013%2011'%3E%3C/svg%3E) and product ![Image 107: A_i](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2016%2014'%3E%3C/svg%3E) is given as:

![Image 108: \lambda_{A_i, C} \ = \ \displaystyle\frac{k  + \alpha_i}{t + \beta_i},](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20120%2037'%3E%3C/svg%3E)

where ![Image 109: \alpha_i](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2014%2010'%3E%3C/svg%3E) and ![Image 110: \beta_i](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2013%2014'%3E%3C/svg%3E) are the shape and rate parameters of gamma distribution for product ![Image 111: A_i](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2016%2014'%3E%3C/svg%3E), ![Image 112: k](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%209%2011'%3E%3C/svg%3E) is the number of repeat purchases, and ![Image 113: t](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%206%2010'%3E%3C/svg%3E) is the time elapsed since the first purchase of product ![Image 114: A_i](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2016%2014'%3E%3C/svg%3E) by customer ![Image 115: C](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2013%2011'%3E%3C/svg%3E).

The ![Image 116: R_{A_i}](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2025%2016'%3E%3C/svg%3E) is then assumed to be a Poisson distribution where the rate parameter is estimated using the above equation.

![Image 117: R_{A_i, C}(t) \ = \ \displaystyle\sum_{m=1}^{\infty} \displaystyle\frac{\lambda^m_{A_i, C} \exp(\lambda_{A_i, C})}{m!}](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20232%2047'%3E%3C/svg%3E)

where ![Image 118: m](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2014%207'%3E%3C/svg%3E) is the expected number of purchases, this model assumes that ![Image 119: Q_{A_i}](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2026%2016'%3E%3C/svg%3E) is fixed, just like the ATD approach.

* * *

### [**Query-Attribute Search Recommendation**](#TOCh3QASR)

Amazon search queries are mostly related to products and are often short (three to four words) and not too descriptive. Such short and undescriptive queries can lead to suboptimal search results because of an information shortage. Amazon leverages attribute recommendations to improve the quality of search recommendations for short queries.

The attribute recommendation (**Figure 9**) takes the customer query as input and recommends implicit attributes that don’t explicitly appear in the search query. For example, for a search query “_iphone 8_,” the attribute recommendation will suggest additional attributes like “**brand:**apple,” “**operating\_system:**ios,” “**complements:** phone case,” and “**substitute\_brand:** samsung.” These additional attributes can enrich the search query and help the search engine provide better results.

[![Image 120](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20700%20172'%3E%3C/svg%3E)](https://lh3.googleusercontent.com/8EIjLimIy5T1deJlOs-UjbArUzN0phZxJc_6YCGLvr7Z8WZgK1kW_COVfXWgt1Pg_9KGEi2e_dr8xXMA743aitiw4fn-aQyzuhX7z8Fv9q3qkj6fKZs1fmbHHlZUwRohSJsvWU8cMFWC0rxbocTXbAs)

**Figure 9:** Overview of Attribute recommendation at Amazon Search (source: [Amazon Science](https://assets.amazon.science/73/50/22098aa04c14958b9bd66901fa64/query-attribute-recommendation-at-amazon-search.pdf)).

The attribute recommendation model comprises three modules: query intent classification, explicit attribute recognition, and implicit attribute recommendation. We will now describe each of these in detail.

* * *

#### [**Query Intent Classification**](#TOCh4QIC)

The intent of a query is defined as the product type intent of the question. For example, the intent of the query “iPhone 14” is “phone,” and for “Nike shoes,” it is “shoes.” Amazon has more than 3000 product types; hence, it is posed as a multi-label classification where a query intent can be classified into one or more product types.

Given a query ![Image 121: q](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%208%2010'%3E%3C/svg%3E) and country id ![Image 122: m](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2014%207'%3E%3C/svg%3E), the model predicts whether each product type is relevant to the question. For training, Amazon uses past customer click behavior from the search logs. These logs contain the number of clicks on each product for a country and query pair.

Each product ![Image 123: a](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%209%207'%3E%3C/svg%3E) is assigned a product type ![Image 124: L_a](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2017%2014'%3E%3C/svg%3E) from a catalog ![Image 125: L](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2011%2011'%3E%3C/svg%3E). Each country-query pair ![Image 126: x_i = (m_i, q_i)](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2085%2018'%3E%3C/svg%3E) is assigned a label,

![Image 127: y_{it} \ = \ \displaystyle\frac{\displaystyle\sum_{L_a = t} N_{ia}}{\displaystyle\sum_a N_{ia}},](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20111%2080'%3E%3C/svg%3E)

where ![Image 128: N_{ia}](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2023%2014'%3E%3C/svg%3E) is the number of clicks on product ![Image 129: a](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%209%207'%3E%3C/svg%3E) for query ![Image 130: q_i](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2011%2010'%3E%3C/svg%3E).

As shown in **Figure 10**, the module uses a BERT (bidirectional encoder representations from transformers) model, which performs classification on top of classification token (\[CLS\]) output embedding. Since it’s a multi-country setting, each country has a different label space consisting of labels observed for products in that marketplace. Hence, we only get labels corresponding to that country’s marketplace. The architecture is shown in the figure below.

* * *

#### [**Explicit Attribute Parsing**](#TOCh4Explicit)

Explicit attribute parsing involves recognizing product attributes from the query (e.g., color, brand, etc.). This module uses a multilingual transformer-based model that performs recognition, as shown below. Each token goes through classification to get its classification label, denoting what attribute this token belongs to. This is illustrated in **Figure 11**:

* * *

#### [**Implicit Attribute Recommendation**](#TOCh4Implicit)

This module first builds an attribute relation graph using two data sources: Amazon product attributes and query attributes. Amazon product attributes are the explicit attributes sellers provide while uploading the product on their platform. For example, iPhone 8 has the attribute brand “apple” and product type “phone.”

The query attribute data is collected from customer search queries, and their corresponding explicit attributes are extracted using the parsing module described before.

Then, the intent classification model obtains each query’s product intent, and each product’s intent is naturally obtained through catalog data. All this information is then used to construct the attribute relation graph shown in **Figure 12**.

[![Image 131](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20700%20268'%3E%3C/svg%3E)](https://lh6.googleusercontent.com/ODjWUu8NneYcf41ZycrNHahu-IyiJqoRBott2JRZ0zcm5ln4UlH7GDgsXAA5pPldCoe7eMztDYT4Hx2HEcvzMP0e4lPus7tA_ifwCRKNFOHv9H79lWcoBfqxdFp0uc-KT61j3qXRaoSSfKx_6Dh3pjk)

**Figure 12:** Implicit attribute recommendation (source: [Amazon Science](https://assets.amazon.science/73/50/22098aa04c14958b9bd66901fa64/query-attribute-recommendation-at-amazon-search.pdf)).

The module used GNN to generate embeddings for each attribute. These embeddings are then used to construct relationships between different attributes. During online inference, given the explicit query attributes and intent, we use the attribute relation graph to recommend implicit attributes by doing a random walk through the graph.

* * *

### What's next? We recommend [PyImageSearch University](https://pyimagesearch.com/pyimagesearch-university/?utm_source=blogPost&utm_medium=bottomBanner&utm_campaign=What%27s%20next%3F%20I%20recommend).

**Course information:**  
84 total classes • 114+ hours of on-demand code walkthrough videos • Last updated: February 2024  
★★★★★ 4.84 (128 Ratings) • 16,000+ Students Enrolled

**I strongly believe that if you had the right teacher you could _master_ computer vision and deep learning.**

Do you think learning computer vision and deep learning has to be time-consuming, overwhelming, and complicated? Or has to involve complex mathematics and equations? Or requires a degree in computer science?

That’s _not_ the case.

All you need to master computer vision and deep learning is for someone to explain things to you in _simple, intuitive_ terms. _And that’s exactly what I do_. My mission is to change education and how complex Artificial Intelligence topics are taught.

If you're serious about learning computer vision, your next stop should be PyImageSearch University, the most comprehensive computer vision, deep learning, and OpenCV course online today. Here you’ll learn how to _successfully_ and _confidently_ apply computer vision to your work, research, and projects. Join me in computer vision mastery.

**Inside PyImageSearch University you'll find:**

*   ✓ **84 courses** on essential computer vision, deep learning, and OpenCV topics
*   ✓ **84 Certificates** of Completion
*   ✓ **114+ hours** of on-demand video
*   ✓ **Brand new courses released _regularly_**, ensuring you can keep up with state-of-the-art techniques
*   ✓ **Pre-configured Jupyter Notebooks in Google Colab**
*   ✓ Run all code examples in your web browser — works on Windows, macOS, and Linux (no dev environment configuration required!)
*   ✓ Access to **centralized code repos for _all_ 536+ tutorials** on PyImageSearch
*   ✓ **Easy one-click downloads** for code, datasets, pre-trained models, etc.
*   ✓ **Access** on mobile, laptop, desktop, etc.

[Click here to join PyImageSearch University](https://pyimagesearch.com/pyimagesearch-university/?utm_source=blogPost&utm_medium=bottomBanner&utm_campaign=What%27s%20next%3F%20I%20recommend)

* * *

[**Summary**](#TOCh2Summary)
----------------------------

In this lesson, we discussed three Amazon recommender systems:

*   related-product recommendation
*   repeat purchase recommendation
*   query attribute recommendation

The goal of the related-product recommendation is to recommend top-![Image 132: k](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%209%2011'%3E%3C/svg%3E) products that are likely to be bought together with the query product. Amazon creates a product graph whose vertices denote all the products and whose edges represent co-purchase (directed) and co-viewed (undirected) relationships.

Graph neural networks (GNNs) are used to learn source and target embeddings for each product based on their relationships. The relevance of a candidate product with respect to the query product is calculated as the dot product between the source representation of the query product and the target representation of the candidate product.

Next, repeat purchase recommendations estimate the probability of a customer purchasing a product again as a function of time from their last purchase of that product. Amazon uses three probabilistic models for modeling repeat purchases.

*   The repeat customer probability model is a time-independent framework based on a frequency-based probabilistic model that computes the repeat customer probability for each product using aggregate repeat purchase statistics of products by customers.
*   The aggregate time distribution (ATD) model is a time-based model that assumes that product purchase density is only a function of past purchase behavior.
*   The Poisson-gamma (PG) model takes customers’ repeat purchases following a homogeneous Poisson process, and the purchase rate across all customers follows a Gamma distribution.

Lastly, the attribute recommendation takes the customer query as input and recommends implicit attributes that don’t explicitly appear in the search query. The attribute recommendation model comprises three modules:

*   query intent classification
*   explicit attribute recognition
*   implicit attribute recommendation

The intent classification model predicts whether each product type is relevant to the query. Explicit attribute parsing involves recognizing product attributes like color, brand, etc., from the query. Finally, the implicit attribute recommendation model builds an attribute relation graph using two data sources: amazon product attributes and query attributes.

However, this is just the tip of the iceberg. There is much more to the Amazon recommendation systems. We highly recommend going through their blog page to learn more.

Stay tuned for an upcoming lesson on YouTube video recommendation systems!

* * *

### [**Citation Information**](#TOCh3Citation)

**Mangla, P.** “Amazon Product Recommendation Systems,” _PyImageSearch_, P. Chugh, A. R. Gosthipaty, S. Huot, K. Kidriavsteva, and R. Raha, eds., 2023, [https://pyimg.co/m8ps5](https://pyimg.co/m8ps5)

@incollection{Mangla\_2023\_Amazon\_Product\_Recommendation\_Systems,
  author = {Puneet Mangla},
  title = {Amazon Product Recommendation Systems},
  booktitle = {PyImageSearch},
  editor = {Puneet Chugh and Aritra Roy Gosthipaty and Susan Huot and Kseniia Kidriavsteva and Ritwik Raha},
  year = {2023},
  url = {https://pyimg.co/m8ps5},
}

* * *

![Image 133: Featured Image](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20500%20276'%3E%3C/svg%3E)

### Unleash the potential of computer vision with Roboflow - Free!

*   Step into the realm of the future by [signing up or logging into your Roboflow account](https://roboflow.com/?ref=pyimagesearch). Unlock a wealth of innovative dataset libraries and revolutionize your computer vision operations.
*   Jumpstart your journey by choosing from our broad array of datasets, or benefit from PyimageSearch’s comprehensive library, crafted to cater to a wide range of requirements.
*   Transfer your data to Roboflow in any of the 40+ compatible formats. Leverage cutting-edge model architectures for training, and deploy seamlessly across diverse platforms, including API, NVIDIA, browser, iOS, and beyond. Integrate our platform effortlessly with your applications or your favorite third-party tools.
*   Equip yourself with the ability to train a potent computer vision model in a mere afternoon. With a few images, you can import data from any source via API, annotate images using our superior cloud-hosted tool, kickstart model training with a single click, and deploy the model via a hosted API endpoint. Tailor your process by opting for a code-centric approach, leveraging our intuitive, cloud-based UI, or combining both to fit your unique needs.
*   Embark on your journey today with absolutely no credit card required. Step into the future with Roboflow.

[Join Roboflow Now](https://roboflow.com/?ref=pyimagesearch)

* * *

![Image 134](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20410%20567'%3E%3C/svg%3E)

#### Join the PyImageSearch Newsletter and Grab My FREE 17-page Resource Guide PDF

Enter your email address below to **join the PyImageSearch Newsletter** and **download my FREE 17-page Resource Guide PDF** on Computer Vision, OpenCV, and Deep Learning.