Recommendation systems benefit both businesses and customers by using data to personalize experiences. They help boost sales, increase customer loyalty, and reduce churn by simplifying choices and keeping users engaged.
We’ve also created a benchmark of the top Python libraries for recommendation systems and included a step-by-step LightFM tutorial.
Dive in to learn what recommendation systems are, how they work, and where they’re used—with real-world examples.
Best python libraries for recommendation systems
These libraries implement machine learning algorithms to process training data and generate personalized recommendations using collaborative or content-based filtering techniques. Additionally, these libraries implement machine learning models to analyze data and uncover patterns, enabling the recommendation engine to suggest relevant items based on user behavior and preferences.
Feature | LightFM | Cornac (BPR) | TensorFlow |
---|---|---|---|
Model Type | Hybrid (Collaborative + Content-based) | Matrix Factorization (BPR) | Collaborative, Content-based, or Hybrid |
Data Type | Explicit & Implicit | Implicit | Explicit & Implicit |
Content Support | Yes (User/Item features) | No | Yes (via feature towers, embeddings, etc.) |
Cold Start | Partially handles (via content features) | No | Yes (if content features are used) |
Evaluation | Precision@K, AUC, Recall@K | NDCG, Precision@K,AUC,Precision@K | Precision@K, Recall@K, AUC |
Use Case | Hybrid systems, metadata use | Implicit feedback ranking | General-purpose, highly customizable recommender systems |
LightFM vs Cornac BPR vs TensorFlow benchmark results
Recommendation Engine | AUC | Precision@10 | Recall@10 |
---|---|---|---|
LightFM | 70% | 0.002 | 0.02 |
Cornac BPR | 70% | 0.004 | 0.04 |
TensorFlow | 90% | 0.08 | 0.8 |
TensorFlow Recommenders performed the best. Its deep learning architecture allows it to capture more complex user-item relationships. LightFM, which works well when metadata is available, didn’t perform as strongly here because we only used behavioral data — it still did better than BPR. Cornac BPR had the lowest recommendation quality, making it more suitable for quick experiments or small-scale applications.
We used our recommendation engine benchmarking methodology to test LightFM, Cornac BPR, and TensorFlow.
What is a recommendation system?
A recommendation system (or recommender system) is a tool designed to provide personalized suggestions to users based on their preferences, behavior, and interactions with a platform. These systems analyze data such as purchase history, browsing history, user demographics, and contextual information to deliver relevant content. Below are the most common types of recommendation systems:
Collaborative filtering techniques:
- Based on patterns of interactions between users and items.
- Includes user-based collaborative filtering (finding similar users) and item-based collaborative filtering (finding similar items).
- Best suited for eCommerce and streaming services.
Content-based filtering techniques:
- Focuses on the attributes of items (item features) and a user’s past interactions (user’s preferences).
- Ideal for identifying specific interests of the target user.
Hybrid recommendation systems:
- Combine collaborative filtering and content-based methods.
- Leverages machine learning models such as deep neural networks and recurrent neural networks for improved predictions.
Recommendation systems key concepts
Matrix factorization basics
Matrix factorization is a core technique in collaborative filtering. It breaks down a large user-item interaction matrix (e.g., ratings or clicks) into smaller matrices that capture hidden patterns or relationships, which are called latent features.
This approach helps reducing data complexity and uncovering meaningful insights, such as a user’s preference for specific genres or an item’s appeal to a particular group.
Understanding implicit data
Implicit data refers to indirect indicators of user preferences, obtained from behaviors rather than explicit feedback like star ratings. Some examples of implicit data include click-through rates, time spent on a page, purchase history, and search patterns.
This type of data is easier to collect at scale and often reflects real-world engagement. However, it can be noisy or ambiguous, such as interpreting whether a long page visit indicates interest or distraction.
Deep learning in recommendations
Deep learning supports recommendation systems by analyzing complex and multi-dimensional data using neural networks. It is particularly effective for session-based recommendations, content understanding, and context-aware suggestions that factor in time, location, or user mood.
These methods can process large and unstructured data like text, images, and videos, learning intricate relationships between features.
Hybrid recommendation approaches
Hybrid recommendation systems combine different techniques, such as collaborative filtering, content-based filtering, and knowledge-based approaches. This integration improves accuracy and addresses challenges like the cold-start problem (new users or items) and sparse data.
Tutorial: building a recommendation system with LightFM
In this tutorial, we’ll build a recommendation engine using LightFM by leveraging both implicit data from user-product interactions. This training data, including various types of customer data, helps the model learn user preferences and make accurate predictions.
The LightFM model we build will predict which products a user is likely to view by estimating their potential interactions with unseen items. The model analyzes data to make these accurate predictions, ensuring that recommendations are tailored to user behavior.
Prerequisites
Before getting started, ensure you have the necessary libraries installed. If you don’t have them, you can install them via pip:
pip install pandas scipy lightfm scikit-learn
For more advanced recommendation systems, natural language processing libraries may also be required.
Dataset overview
In this tutorial, we’ll be using a retail e-commerce dataset, which contains information about user interactions with products. The dataset includes the following columns:
- visitorid: A unique identifier for the visitor (user).
- itemid: A unique identifier for the item (product).
- event: The interaction event, in this case, we’re only interested in ‘view’ events.
The dataset may also contain unstructured data that needs to be processed.
A sample entry in the dataset would look like this:
timestamp, visitorid, event, itemid
1435193216976, 50734, view, 4442
For simplicity, we’re going to filter out only the ‘view’ events where users have interacted with products. We’ll then use this information to build the recommendation model.
Step-by-step recommendation system guide
1. Load and prepare the data
First, we need to load the dataset and preprocess it for training. The key columns we need are visitorid, itemid, and event. We will also filter out ‘view’ events and convert categorical variables (visitorid and itemid) into numerical codes to optimize memory usage.
import pandas as pd
Load the dataset:
df = pd.read_csv('interactions.csv', usecols=['visitorid', 'itemid', 'event'])
Filter out only ‘view’ events:
df = df[df['event'] == 'view']
Convert visitorid and itemid to category type to save memory:
df['visitorid'] = df['visitorid'].astype('category')
df['itemid'] = df['itemid'].astype('category')
2. Create the user-item matrix
Next, we’ll convert the visitorid and itemid columns into numerical representations and build a sparse matrix that will serve as our input to the LightFM model. We will use scipy to create a sparse matrix, which is memory-efficient for large datasets.
from scipy.sparse import coo_matrix, csr_matrix
Convert visitorid and itemid to numeric codes:
user_ids = df['visitorid'].cat.codes
item_ids = df['itemid'].cat.codes
Define the matrix dimensions:
num_users = len(df['visitorid'].cat.categories)
num_items = len(df['itemid'].cat.categories)
Create the sparse matrix (COO format):
sparse_matrix = coo_matrix((df['event'].notnull(), (user_ids, item_ids)), shape=(num_users, num_items))
4. Split the data into training and testing sets
We’ll now split the sampled data into training and testing sets using train_test_split from scikit-learn. This will allow us to evaluate the performance of the recommendation model on unseen data.
from sklearn.model_selection import train_test_split
Split the data into training and test sets
train, test = train_test_split(df, test_size=0.2, random_state=42)
Convert the training and test data to sparse format:
train_sparse = csr_matrix((train['event'].notnull(), (train['visitorid'].cat.codes, train['itemid'].cat.codes)), shape=(num_users, num_items))
test_sparse = csr_matrix((test['event'].notnull(), (test['visitorid'].cat.codes, test['itemid'].cat.codes)), shape=(num_users, num_items))
5. Train the LightFM model
Now that we have prepared the data, we can train the LightFM model. We’ll use the WARP (Weighted Approximate-Rank Pairwise) loss function, which is effective for recommendation tasks.
from lightfm import LightFM
import time
Initialize the LightFM model with WARP loss:
model_lightfm = LightFM(loss='warp')
Start training the model:
start_time = time.time()
model_lightfm.fit(train_sparse, epochs=30, num_threads=2)
training_time = time.time() - start_time
Print the training time:
print(f"Training time: {training_time:.4f} seconds")
6. Evaluate the model
Once the model is trained, we can evaluate its performance using metrics like AUC (Area Under the Curve), Precision@10, and Recall@10. These metrics give us insights into how well the model is performing.
from lightfm.evaluation import auc_score, precision_at_k, recall_at_k
Calculate AUC on the test data:
test_auc = auc_score(model_lightfm, test_sparse).mean()
print(f"Test AUC: {test_auc:.4f}")
Calculate Precision@10 and Recall@10:
precision = precision_at_k(model_lightfm, test_sparse, k=10).mean()
recall = recall_at_k(model_lightfm, test_sparse, k=10).mean()
print(f"Precision@10: {precision:.4f}")
print(f"Recall@10: {recall:.4f}")
In this tutorial, we’ve built a simple recommendation system using the LightFM library. We went through the process of loading the dataset, preprocessing the data, training a recommendation model, and evaluating its performance. The model can be further tuned and optimized based on the specific needs of your application.
Applicable areas for recommendation systems

Almost any business can benefit from a recommendation system. There are two important aspects that determine the level of benefit a business can gain from the technology.
- The breadth of data: A business serving only a handful of customers that behave in different ways will not receive many benefits from an automated recommendation system. Humans are still much better than machines in the area of learning from a few examples. In such cases, your employees will use their logic and qualitative and quantitative understanding of customers to make accurate recommendations.
- The depth of data: Having a single data point on each customer is also not helpful to recommendation systems. Deep data about customers’ online activities and, if possible, offline purchases can guide accurate recommendations.
Here are some of the most common industries where recommendation systems are applied:
eCommerce
eCommerce platforms leverage recommendation systems to enhance the shopping experience by suggesting relevant products to users.
These systems analyze past purchases, browsing history, and preferences to recommend items like “Customers who bought this also bought” or “Frequently bought together.”
This process improves sales and boosts the average order value and also enhances customer satisfaction by saving users time and effort.
Real-life example: Amazon
Amazon.com uses item-to-item collaborative filtering recommendations on most pages of their website and e-mail campaigns. According to McKinsey, 35% of Amazon purchases are thanks to recommendation systems.1
Entertainment
In the entertainment industry, recommendation systems help users discover movies, music, TV shows, or books tailored to their tastes. By analyzing viewing or listening habits, these systems can provide personalized content to increase user engagement and time spent on the platform.
Real-life example: Netflix
Netflix uses a combination of collaborative filtering and content-based filtering to suggest shows and movies, leading to 80% of watched content being driven by recommendations.
The Netflix Prize was a competition launched by Netflix in October 2006 to improve its movie recommendation system. The challenge offered a $1 million prize to the team or individual who could achieve at least a 10% improvement in the accuracy of predictions compared to Netflix’s existing recommendation algorithm.2
Real-life example: Spotify
Every week, Spotify generates a new customized playlist for each subscriber called “Discover Weekly” which is a personalized list of 30 songs based on users’ unique music tastes. Their acquisition of Echo Nest, a music intelligence and data-analytics startup, enable them to create a music recommendation engine that uses three different types of recommendation models:3
- Collaborative filtering: Filtering songs by comparing users’ historical listening data with other users’ listening history.
- Natural language processing: Scraping the internet for information about specific artists and songs. Each artist or song is then assigned a dynamic list of top terms that changes daily and is weighted by relevance. The engine then determines whether two pieces of music or artists are similar.
- Audio file analysis: The algorithm each individual audio file’s characteristics, including tempo, loudness, key, and time signature, and makes recommendations accordingly.
Social media
Social media platforms use recommendation systems to suggest friends, groups, pages, posts, or ads based on user interactions, preferences, and connections. These suggestions enhance user interaction, encourage content discovery, and generate advertising revenue.
Real-life example: Meta
Meta employs AI systems to deliver personalized content recommendations on Facebook and Instagram, even from sources users don’t follow. This approach enhances user experience by introducing diverse content and supports creators in reaching broader audiences. The recommendation process involves:
- Content understanding: Utilizing AI models to analyze and interpret various content types including images, text, audio, and video, to understand their semantic meanings.
- Preference understanding, retrieval, and ranking: Developing systems that easily filter large amounts of content to identify and rank those most relevant to individual user interests.
This AI-driven strategy enables Meta to present users with engaging content beyond their immediate network to foster deeper exploration of interests and enhance overall platform engagement.4
Healthcare
Healthcare recommendation systems suggest treatment options, health resources, or preventive measures tailored to patient data such as medical history and lifestyle. Incorporating AI into healthcare improves care quality and reduces healthcare costs. Check out generative AI in healthcare to learn more.
Real-life example: Ada Healthcare
Ada Health is an AI-powered platform designed to assist users in managing their health by providing personalized medical guidance. Users can enter their symptoms to receive assessments that suggest possible conditions and recommend appropriate next steps The platform’s AI system is continually optimized by a team of medical experts to ensure accuracy and reliability.
In addition to serving individual users, Ada offers enterprise solutions aimed at improving healthcare outcomes. These solutions assist partners in informing health decisions, enhancing triage processes, and reducing avoidable costs.5
Retail
In retail, recommendation systems are used for personalized shopping experiences, in-store recommendations, and inventory suggestions. These systems help retailers optimize stock management, improve sales, and increase customer satisfaction.
Real-life example: Rappi with Amazon Personalize
Rappi, an on-demand delivery service in Latin America, collaborated with Amazon Personalize to enhance customer engagement and boost sales by implementing a personalized recommendation system within its app.
By leveraging Amazon Personalize, Rappi developed a feature called “Just For You” (JFY), which analyzes user behavior and preferences to provide tailored product recommendations displayed in a dedicated section of the app.
This personalization strategy led to a 102% increase in click-through rates and a 147% rise in revenue from personalized recommendations. Additionally, customer engagement improved, and the occurrence of underperforming products decreased.6
Finance and banking
Financial institutions use recommendation systems to suggest investment options, credit cards, or insurance products based on a user’s financial behavior and goals. Check out Gen AI use cases in banking to learn more about how generative AI can be used in finance and banking.
Gaming
Gaming platforms use recommendation systems to suggest in-game purchases, new games, or connect players based on their preferences, playing habits, and social interactions. This enhances the gaming experience and drives revenue.
Real-life example: Glance with Google Cloud
Glance, a subsidiary of InMobi, partnered with Google Cloud to build a personalized game recommendation system for their mobile gaming platform, Nostra, which engages over 220 million users via lock screens.
By analyzing user and game data with interaction data, they identified patterns like optimal engagement times and game preferences. This collaboration significantly improved user engagement.7
These areas are particularly suitable for recommendation systems because they involve industries that generate large volumes of user and item data, providing a rich foundation for accurate predictions and insights.
Users in these fields increasingly expect personalized experiences tailored to their preferences which would making recommendations a critical feature for meeting customer demands.
Moreover, recommendation systems open up significant revenue opportunities by driving upselling, cross-selling, and higher engagement rates. By offering tailored suggestions, these systems enhance customer retention, fostering long-term loyalty and sustained user interaction.
Setting up a recommendation system
While most companies would benefit from adopting an existing solution, companies in niche categories or very high scale could experiment with building their own recommendation engine.
1. Using an out-of-the-box solution
Recommendation systems are one of the earliest and most mature AI use cases.
The advantages of this approach include fast implementation and highly accurate results for most cases:
- Including a code snippet of the vendor can be enough to get started.
- Solutions tend to be accurate since vendors use data from thousands of transactions of their customers in an anonymized manner to improve their models.
To pick the right system, you can use historical or, even better, live data to test the effectiveness of different systems quickly.
2. Building your own solution
This can make sense if:
- you are in a niche domain where recommendation engines were not used before or
- you own one of the world’s largest marketplaces where slightly better recommendations can make an important difference in your business outcomes.
Recommendation systems in the market today use logic like: customers with the similar purchase and browsing histories will purchase similar products in the future. To make such a system work, you either need a large number of historical transactions or detailed data on your user’s behavior on other websites. If you need such data, you could search for it in data marketplaces.
More data and better algorithms improve recommendations. You need to make use of all relevant data in your company, and you could expand your customer data with 3rd party data. If a regular customer of yours has been looking for red sneakers on other websites, why shouldn’t you show them a great pair when they visit your website?
3. Working with a consultant to build your own solutions
A slightly better recommendation engine could boost a company’s sales by a few percentage points, which could make a dramatic change in the profitability of a company with low-profit margins. Therefore, it can make sense to invest in building better recommendation engines if the company is not having satisfactory results from existing solution providers in the market.
4. Running a data science competition to build your own solution
One possible approach is to use the wisdom of the crowd to build such systems. Companies can use encrypted historical data, launch data science competitions, or work with consultants and get models providing highly effective recommendations.
Benefits of recommendation systems
Increased sales and conversion
Recommendation systems provide a low-effort, high-return strategy for boosting sales. By leveraging data about user preferences and behavior, these systems effectively match customers with products or services they are likely to buy:
- Automated efficiency: Once implemented, a recommendation system operates continuously without significant manual intervention. Unlike traditional marketing efforts that require active planning and execution, recommendation systems deliver personalized suggestions instantly.
- Enhanced relevance: Customers are more likely to purchase when presented with options that align closely with their preferences which would lead to an increase in conversion rates.
- Cross-selling and upselling opportunities: By suggesting complementary or higher-value products, businesses can generate additional revenue from the same customer base.
Increased user satisfaction
Customer satisfaction is key to building trust and encouraging repeat purchases. Recommendation systems contribute to this by simplifying and enhancing the shopping experience:
- Personalized journeys: Tailored suggestions make customers feel understood, while creating a sense of personalization that resonates with their needs.
- Time-saving: By proactively presenting relevant products, recommendation systems can reduce the time and effort required to find suitable items.
- Discovering new products: Customers are often happy to discover products they weren’t explicitly searching for but find appealing, with algorithm-driven recommendations.
Increased customer loyalty
Loyal customers are essential to sustained business growth. Recommendation systems can play a critical role in fostering brand loyalty:
- Familiarity and ease of use: When customers frequently interact with a platform that consistently provides relevant recommendations, they become more comfortable and familiar with it. This familiarity increases their likelihood of returning.
- Trust in personalization: Offering consistently valuable suggestions builds trust in the brand, also making customers feel that the company understands their preferences.
Reduced churn
Customer retention is often more cost-effective than acquiring new customers, and recommendation systems can be a powerful tool for reducing churn:
- Re-engagement through personalized emails: Email marketing campaigns powered by AI systems can target inactive customers with tailored product suggestions.
- Cost-effective incentives: While discounts and coupons can be costly, pairing them with personalized recommendations can ensure they are used effectively to maximize the chances of conversion.
- Predictive behavior analysis: Advanced recommendation systems analyze customer behavior to identify those at risk of churning. Businesses can then proactively engage these customers with targeted suggestions or incentives to retain them.
Recommendation engine benchmark methodology
In this study, we focused on building and evaluating recommendation systems based on implicit feedback data, specifically user interactions with products. The dataset used in our analysis contains three key elements: visitorid, itemid, and interaction types such as view, add to cart, and transaction. Since users did not explicitly rate items but interacted through these behaviors, we considered this data as implicit feedback.
We tested three different recommendation models to evaluate their effectiveness in handling implicit data:
- LightFM: A hybrid model that uses both collaborative filtering and content-based methods. We leveraged the WARP (Weighted Approximate-Rank Pairwise) loss function to train the model. The focus was on predicting the likelihood of a user viewing a product by analyzing their historical interactions with items.
- Cornac BPR (Bayesian Personalized Ranking): A collaborative filtering-based model designed to rank items based on user interactions. It uses implicit feedback to learn the preferences of users by optimizing the ranking of relevant items over irrelevant ones.
- TensorFlow Recommenders: A deep learning-based framework that uses embeddings to represent both users and items, capturing complex relationships between them. The model is trained on implicit interactions, with a retrieval task to predict the most relevant items for each user.
The models were trained to predict the likelihood of a user interacting with a product, specifically focusing on the view event as the target behavior. Our goal was to estimate which products users are most likely to engage with, based on their past behavior. After training, we evaluated the models using test data to ensure they could generalize well to unseen interactions.
We evaluated the performance of the models based on three commonly used metrics in recommender systems:
- AUC (Area Under the Curve): A metric that evaluates how well the model ranks relevant items higher than irrelevant ones. An AUC score closer to 1 indicates better ranking performance.
- Precision@10: Measures how many of the top 10 recommended items are actually relevant (i.e., interacted with by the user). Higher values indicate better recommendation accuracy.
- Recall@10: Measures how many relevant items (from the user’s interactions) appear within the top 10 recommendations. This metric is crucial for understanding how well the model captures user preferences.
By comparing these metrics across the three models, we identified the best-performing model in terms of both ranking relevant items and retrieving those items accurately in the top recommendations.
Conclusion
Recommendation systems have proven effective in enhancing customer engagement and driving business growth. By analyzing user preferences and behaviors, these systems offer personalized suggestions that contribute to increased sales, improved customer loyalty, and reduced customer churn.
Evidence from various industries indicates that eCommerce platforms have experienced increases in conversion rates and average order value, while entertainment platforms have seen enhanced user engagement through tailored content recommendations.
Industries such as eCommerce, entertainment, social media, retail, healthcare, and finance benefit from the implementation of recommendation systems.
In healthcare and finance, recommendation systems have supported more personalized services, improving customer satisfaction and outcomes. These results demonstrate the effectiveness of recommendation systems in enhancing user experience and driving business performance across various sectors.
External Links
- 1. How retailers can keep up with consumers | McKinsey. McKinsey & Company
- 2. Netflix Research.
- 3. Discover Weekly: How Spotify is Changing the Way We Consume Music - Technology and Operations Management.
- 4. The AI behind unconnected content recommendations on Facebook and Instagram.
- 5. Health. Powered by Ada..
- 6. Building a Powerful Retail Personalization Engine Using Amazon Personalize | Rappi Case Study | AWS.
- 7. Nostra from Glance, Gaming Recommendation at Scale with Google Cloud AI | Google Cloud Blog. Google Cloud
Comments
Your email address will not be published. All fields are required.