The Challenge

In today’s competitive retail landscape, providing a personalized shopping experience has become more critical than ever. With the advent of e-commerce and digital transformation, customers now expect retailers to understand their preferences and deliver tailored recommendations. This is where retail recommendation models come into play. These sophisticated algorithms analyze vast amounts of data to predict customer behavior and suggest products that meet individual needs and tastes.

Retail recommendation models leverage machine learning and artificial intelligence to process customer data, including past purchases, browsing history, and even demographic information. By identifying patterns and correlations within this data, these models can predict what products a customer is likely to be interested in, thereby enhancing their shopping experience and increasing the likelihood of purchase.

One of the most well-known examples of retail recommendation systems is Amazon’s “Customers who bought this item also bought” feature, which uses collaborative filtering to recommend products based on the purchasing behavior of similar users. Other techniques, such as content-based filtering and hybrid models, are also commonly used to provide more accurate and diverse recommendations.

Implementing an effective recommendation system can significantly boost a retailer’s sales and customer loyalty. It allows retailers to offer a more engaging and personalized shopping journey, driving higher conversion rates and fostering long-term customer relationships. In this blog post, we will explore the various types of recommendation models, how they work, and the benefits they bring to the retail industry. Whether you are a retailer looking to enhance your customer experience or a tech enthusiast curious about the workings of these models, this article will provide valuable insights into the world of retail recommendation systems.

Project Overview

To achieve the task we have to clearly see the client’s goal and the available dataset. After we created the recommendation model, we also need a support from client side to go live with the project.

Used Technology:

  • Digital Ocean
  • Bash
  • Python

Within Python we are going to use LightFm. It is a Python library that implements several well-known recommendation algorithms for handling both implicit and explicit feedback.

Additionally, it enables the integration of both item and user metadata into standard matrix factorization techniques. By representing each user and item as the sum of the latent features of their characteristics, it allows recommendations to adapt to new items (through item features) and new users (through user features).

Data Preprocessing and Exploration

First of all, it is important to familiarize ourselves with the basic dataset. From this, we can already see what accuracy we can achieve with the recommender system.

We have two separate dataset:

  1. events.csv
  2. items.csv

What type of data are in the files?

Events.csv contains the interaction events between visitor and items. It can be page view, add to cart or purchase events.

Copy to Clipboard

 

Items.csv file only contains information about the items. If the BCI group is the same for two products, we can be sure that the two products are almost identical.

Copy to Clipboard

We have 780,650 lines of data like this. This amount is data is enough to separate the data to training and test dataset.

Training Dataset

The training dataset is used to fit the model. The model learns the relationships between the input features and the target variable during this phase. The primary goal is to minimize the error on the training data.

Test Dataset

The test dataset is used to evaluate the final model’s performance after it has been trained and tuned. This dataset should not be used during training or validation to ensure an unbiased assessment. It helps in the following ways:

Performance Evaluation: The test dataset provides a final evaluation metric (e.g., accuracy, precision, recall, etc.) to assess how well the model will perform on unseen data.

Generalization: It helps in understanding how well the model generalizes to new data that was not part of the training or validation process.

Recommendation Model Preparation

Create Matrix

We have to create matrix and string together the two csv dataset. So we are going to make interaction matrix and item feature matrix.

Copy to Clipboard

The Recommendation Model

Define Variables

First we defined the basic variables. It helps us to iterate faster during training and later maintain the code.

The earning_schedule is string and can be ‘adagrad’ or ‘adadelta’.
  1. Adagrad (Adaptive Gradient Algorithm):
    • Adagrad is an optimization algorithm that adapts the learning rate for each parameter individually during training.
    • It adjusts the learning rate based on the historical gradients, scaling it down for parameters that have frequently been updated, which helps in dealing with sparse data and scenarios where certain parameters need more fine-tuning than others.
    • One limitation of Adagrad is that it can shrink the learning rate too much over time, leading to slow convergence or even stopping the learning process.
  2. Adadelta:
    • Adadelta is an extension of Adagrad designed to address the problem of the diminishing learning rates.
    • Instead of accumulating all past squared gradients, Adadelta restricts the window of accumulated past gradients to a fixed size, essentially using a decaying average of past squared gradients.
    • This allows the algorithm to maintain a more consistent learning rate and improves performance on a broader range of tasks.

Both algorithms are used to optimize the loss function during the training process, helping the model to converge to a better solution by updating the model parameters effectively.

 

In LightFM, the loss parameter specifies the type of loss function to be used for training the recommendation model. Here’s a brief explanation of each type. To reduce loss we can choose the following options: ‘logistic’, ‘bpr’, ‘warp’, ‘warp-kos’.
  1. Logistic:
    • The logistic loss function is used for logistic regression. It’s suitable for binary classification problems where the goal is to predict the probability of a positive event. In the context of recommendation systems, it helps in distinguishing between relevant and irrelevant items.
  2. BPR (Bayesian Personalized Ranking):
    • BPR is a pairwise ranking loss function. It optimizes the ranking of items by focusing on the relative order rather than the absolute scores. It is particularly useful for implicit feedback data, where the goal is to ensure that relevant items are ranked higher than irrelevant ones.
  3. WARP (Weighted Approximate-Rank Pairwise):
    • WARP is another pairwise ranking loss function but it also takes into account the rank of the positive item. The loss is weighted by the rank of the positive item, giving more importance to correctly ranking higher-ranked items. It’s designed to directly optimize the top of the ranked list, which is often the most important part in recommendation tasks.
  4. WARP-kos (WARP-k k-Ordered Statistics):
    • WARP-kos is a variant of WARP that also optimizes for the rank of positive items but with an additional focus on the k-th order statistics. This means it considers the k-th highest ranking items during optimization, which can be useful for tasks where the top-k recommendations are critical.

Each of these loss functions serves a different purpose and is chosen based on the specific requirements and characteristics of the recommendation problem being solved.

Copy to Clipboard

Train the model

Let’s train the LightFm model with the above variables and matrices.

Copy to Clipboard

Test the model

OK, we have a model. Let’s see how much accuracy we can achieve.

 

AUC

It indicates that, on average, the model correctly distinguishes between relevant and irrelevant items 84.44% of the time. A higher AUC value, closer to 100%, signifies better model performance in ranking relevant items higher than irrelevant ones.

Copy to Clipboard

Precision

An Average Precision of 4.30% indicates that, on average, 4.30% of the items recommended are relevant to the users. This metric is particularly useful for assessing the quality of top-k recommendations.

Copy to Clipboard

Recall

An Average Recall of 30.14% indicates that, on average, the model is able to recommend 30.14% of the relevant items available. This metric helps to understand how well the model captures the total set of relevant items for each user.

Copy to Clipboard

Recall at K

It measures the proportion of relevant items that are included in the top-K recommendations, averaged across all users. An Average Recall at K of 21.15% indicates that, on average, 21.15% of the relevant items are found within the top-K recommendations made by the model. This metric is useful for assessing how well the model performs when only considering the top-K items, which is often crucial for recommendation systems where users typically only look at the top suggestions.

Copy to Clipboard

Conclusion

Overall, the model demonstrates a good ability to rank relevant items highly (as indicated by the high AUC), but it struggles with precision and recall, especially within the top-K recommendations. To improve its effectiveness, efforts should be made to enhance the precision, ensuring that more recommended items are relevant, and to increase recall, capturing a larger proportion of relevant items. Enhancing these aspects will provide users with more accurate and useful recommendations, particularly in the top suggestions they are most likely to consider.

 

Recommendation models enhance user experience by providing personalized, relevant, and engaging content, leading to higher interaction rates, increased sales, and stronger customer loyalty. These factors collectively contribute to improved conversion rates and revenue growth for businesses.

  1. Personalization:
    • Enhanced User Experience: By tailoring recommendations to individual preferences, users are more likely to engage with content or products that match their interests.
    • Increased Satisfaction: Personalized suggestions make users feel understood and valued, increasing their overall satisfaction and likelihood of returning.
  2. Relevance:
    • Targeted Marketing: Recommendations based on user behavior and preferences ensure that marketing efforts are directed towards users most likely to be interested in specific products or services.
    • Efficient Discoverability: Users can discover products they might not have found on their own, increasing the chances of making a purchase.
  3. Engagement:
    • Higher Interaction Rates: Personalized recommendations often result in higher click-through rates, as users are more inclined to explore items that resonate with their tastes.
    • Increased Time Spent: Users are likely to spend more time on the platform exploring recommended items, leading to more opportunities for conversions.
  4. Cross-Selling and Up-Selling:
    • Complementary Products: Recommending items that complement previous purchases encourages users to buy additional products.
    • Premium Products: Suggesting higher-value items or upgrades can lead to increased average order values.
  5. Retention:
    • Loyalty Building: Consistent, relevant recommendations can build brand loyalty, encouraging repeat visits and purchases.
    • Reduced Churn: Satisfied users are less likely to leave the platform, ensuring a stable and growing customer base.
  6. Data Utilization:
    • Behavioral Insights: Recommendation models leverage vast amounts of user data to continuously improve accuracy and relevance, adapting to changing user preferences.
    • Market Trends: Analyzing aggregate recommendation data can reveal market trends, helping businesses adjust their strategies to meet evolving demands.
  7. Efficiency:
    • Automated Personalization: Automated recommendation systems reduce the need for manual curation, saving time and resources while providing consistent and scalable personalization.
    • Resource Optimization: By focusing marketing efforts on high-probability leads, businesses can optimize their resource allocation, increasing overall efficiency.

 

Do you want to booth your revenue with recommendation model?

Contact us!