{
  "source_file": "0930",
  "source_platform": "Medium",
  "author": "Ransaka Ravihara",
  "title_listed": "Learning to Rank for Product Recommendations",
  "keywords": "Learning to Rank,XGBoost,推荐",
  "domain": "机器学习",
  "content_type": "深度技术解析",
  "is_paid_flag": "部分免费/会员墙",
  "url": "https://towardsdatascience.com/learning-to-rank-for-product-recommendations-a113221ad8a7/",
  "publish_date": "2022-09",
  "corpus_stage": "预训练/SFT",
  "notes": "",
  "id": "37a77accefed",
  "collected_at": "2026-10-01T23:40:06",
  "title": "Learning to Rank for Product Recommendations | Towards Data Science",
  "body_markdown": "![Revisit consent button](https://cdn-cookieyes.com/assets/images/revisit.svg)\nWe value your privacy\nWe use cookies to enhance your browsing experience, serve personalised ads or content, and analyse our traffic. By clicking \"Accept All\", you consent to our use of cookies.\nCustomise Reject All Accept All\nCustomise Consent Preferences ![](https://cdn-cookieyes.com/assets/images/close.svg)\nWe use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.\nThe cookies that are categorised as \"Necessary\" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... Show more\nNecessaryAlways Active\nNecessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.\n  * Cookie\nBCTempID\n  * Duration\n10 minutes\n  * Description\nNo description available.\n\n\n  * Cookie\n__cf_bm\n  * Duration\n1 hour\n  * Description\nThis cookie, set by Cloudflare, is used to support Cloudflare Bot Management. \n\n\n  * Cookie\nAWSALBCORS\n  * Duration\n7 days\n  * Description\nAmazon Web Services set this cookie for load balancing.\n\n\n  * Cookie\n_cfuvid\n  * Duration\nsession\n  * Description\nCloudflare sets this cookie to track users across sessions to optimize user experience by maintaining session consistency and providing personalized services\n\n\n  * Cookie\nli_gc\n  * Duration\n6 months\n  * Description\nLinkedin set this cookie for storing visitor's consent regarding using cookies for non-essential purposes.\n\n\n  * Cookie\n__hssrc\n  * Duration\nsession\n  * Description\nThis cookie is set by Hubspot whenever it changes the session cookie. The __hssrc cookie set to 1 indicates that the user has restarted the browser, and if the cookie does not exist, it is assumed to be a new session.\n\n\n  * Cookie\n__hssc\n  * Duration\n1 hour\n  * Description\nHubSpot sets this cookie to keep track of sessions and to determine if HubSpot should increment the session number and timestamps in the __hstc cookie.\n\n\n  * Cookie\nwpEmojiSettingsSupports\n  * Duration\nsession\n  * Description\nWordPress sets this cookie when a user interacts with emojis on a WordPress site. It helps determine if the user's browser can display emojis properly.\n\n\n  * Cookie\nBCSessionID\n  * Duration\n1 year 1 month 4 days\n  * Description\nBlueconic sets this cookie as a unique identifier for the BlueConic profile.\n\n\n  * Cookie\n_octo\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\nlogged_in\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\n__Secure-YEC\n  * Duration\npast\n  * Description\nYouTube sets this cookie to stores the user's video player preferences using embedded YouTube video\n\n\n  * Cookie\n__eoi\n  * Duration\n6 months\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nAWSALBTGCORS\n  * Duration\n7 days\n  * Description\nNo description available.\n\n\n  * Cookie\nlogin-status-p\n  * Duration\npast\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nAWSALBTG\n  * Duration\n7 days\n  * Description\nNo description available.\n\n\n  * Cookie\ncsrf_token\n  * Duration\nsession\n  * Description\nNo description available.\n\n\n  * Cookie\ntoken_v2\n  * Duration\n1 day\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nD\n  * Duration\n1 year\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nPHPSESSID\n  * Duration\nsession\n  * Description\nThis cookie is native to PHP applications. The cookie stores and identifies a user's unique session ID to manage user sessions on the website. The cookie is a session cookie and will be deleted when all the browser windows are closed.\n\n\n  * Cookie\nVISITOR_PRIVACY_METADATA\n  * Duration\n6 months\n  * Description\nYouTube sets this cookie to store the user's cookie consent state for the current domain. \n\n\n  * Cookie\ncookietest\n  * Duration\nsession\n  * Description\nThe cookietest cookie is typically used to determine whether the user's browser accepts cookies, essential for website functionality and user experience.\n\n\n  * Cookie\n__Host-airtable-session\n  * Duration\n1 year\n  * Description\nThis cookie is used to enable us to integrate the services of Airtable.\n\n\n  * Cookie\n__Host-airtable-session.sig\n  * Duration\n1 year\n  * Description\nThis cookie is used to enable us to integrate the services of Airtable.\n\n\n  * Cookie\nm\n  * Duration\n1 year 1 month 4 days\n  * Description\nStripe sets this cookie for fraud prevention purposes. It identifies the device used to access the website, allowing the website to be formatted accordingly.\n\n\n  * Cookie\nBIGipServer*\n  * Duration\nsession\n  * Description\nMarketo sets this cookie to collect information about the user's online activity and build a profile about their interests to provide advertisements relevant to the user. \n\n\n  * Cookie\n__cfruid\n  * Duration\nsession\n  * Description\nCloudflare sets this cookie to identify trusted web traffic.\n\n\n  * Cookie\n_GRECAPTCHA\n  * Duration\n6 months\n  * Description\nGoogle Recaptcha service sets this cookie to identify bots to protect the website against malicious spam attacks.\n\n\n  * Cookie\n__Secure-YNID\n  * Duration\n6 months\n  * Description\nGoogle cookie used to protect user security and prevent fraud, especially during the login process.\n\n\n  * Cookie\ncookieyes-consent\n  * Duration\n1 year\n  * Description\nCookieYes sets this cookie to remember users' consent preferences so that their preferences are respected on subsequent visits to this site. It does not collect or store any personal information about the site visitors.\n\n\nFunctional\nFunctional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.\n  * Cookie\nlidc\n  * Duration\n1 day\n  * Description\nLinkedIn sets the lidc cookie to facilitate data center selection.\n\n\n  * Cookie\nbrw\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\nbrwConsent\n  * Duration\n5 minutes\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nWMF-Uniq\n  * Duration\n1 year\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nloom_anon_comment\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\nloom_referral_video\n  * Duration\nsession\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nVISITOR_INFO1_LIVE\n  * Duration\n6 months\n  * Description\nA cookie set by YouTube to measure bandwidth that determines whether the user gets the new or old player interface.\n\n\n  * Cookie\nyt-remote-connected-devices\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to store the user's video preferences using embedded YouTube videos.\n\n\n  * Cookie\nytidb::LAST_RESULT_ENTRY_KEY\n  * Duration\nNever Expires\n  * Description\nThe cookie ytidb::LAST_RESULT_ENTRY_KEY is used by YouTube to store the last search result entry that was clicked by the user. This information is used to improve the user experience by providing more relevant search results in the future.\n\n\n  * Cookie\nyt-remote-device-id\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to store the user's video preferences using embedded YouTube videos.\n\n\n  * Cookie\nyt-remote-session-name\n  * Duration\nsession\n  * Description\nThe yt-remote-session-name cookie is used by YouTube to store the user's video player preferences using embedded YouTube video.\n\n\n  * Cookie\nyt-remote-fast-check-period\n  * Duration\nsession\n  * Description\nThe yt-remote-fast-check-period cookie is used by YouTube to store the user's video player preferences for embedded YouTube videos.\n\n\n  * Cookie\nyt-remote-session-app\n  * Duration\nsession\n  * Description\nThe yt-remote-session-app cookie is used by YouTube to store user preferences and information about the interface of the embedded YouTube video player.\n\n\n  * Cookie\nyt-remote-cast-available\n  * Duration\nsession\n  * Description\nThe yt-remote-cast-available cookie is used to store the user's preferences regarding whether casting is available on their YouTube video player.\n\n\n  * Cookie\nyt-remote-cast-installed\n  * Duration\nsession\n  * Description\nThe yt-remote-cast-installed cookie is used to store the user's video player preferences using embedded YouTube video.\n\n\n  * Cookie\ncp_session\n  * Duration\n3 months\n  * Description\nCodepen sets this cookie for Help systems found in the website.\n\n\n  * Cookie\nloid\n  * Duration\n1 year 1 month 4 days\n  * Description\nThis cookie is set by the Reddit. The cookie enables the sharing of content from the website onto the social media platform.\n\n\nAnalytics\nAnalytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.\n  * Cookie\n__hstc\n  * Duration\n6 months\n  * Description\nHubspot set this main cookie for tracking visitors. It contains the domain, initial timestamp (first visit), last timestamp (last visit), current timestamp (this visit), and session number (increments for each subsequent session).\n\n\n  * Cookie\nhubspotutk\n  * Duration\n6 months\n  * Description\nHubSpot sets this cookie to keep track of the visitors to the website. This cookie is passed to HubSpot on form submission and used when deduplicating contacts.\n\n\n  * Cookie\n_ga\n  * Duration\n1 year 1 month 4 days\n  * Description\nGoogle Analytics sets this cookie to calculate visitor, session and campaign data and track site usage for the site's analytics report. The cookie stores information anonymously and assigns a randomly generated number to recognise unique visitors.\n\n\n  * Cookie\n_ga_*\n  * Duration\n1 year 1 month 4 days\n  * Description\nGoogle Analytics sets this cookie to store and count page views.\n\n\n  * Cookie\n__Host-psifi.analyticsTrace\n  * Duration\n6 hours\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\n__Host-psifi.analyticsTraceV2\n  * Duration\n6 hours\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\n_gh_sess\n  * Duration\nsession\n  * Description\nGitHub sets this cookie for temporary application and framework state between pages like what step the user is on in a multiple step form.\n\n\n  * Cookie\nYSC\n  * Duration\nsession\n  * Description\nYSC cookie is set by Youtube and is used to track the views of embedded videos on Youtube pages.\n\n\n  * Cookie\najs_anonymous_id\n  * Duration\n1 year\n  * Description\nThis cookie is set by Segment to count the number of people who visit a certain site by tracking if they have visited before.\n\n\n  * Cookie\nvuid\n  * Duration\n1 year 1 month 4 days\n  * Description\nVimeo installs this cookie to collect tracking information by setting a unique ID to embed videos on the website. \n\n\nPerformance\nPerformance cookies are used to understand and analyse the key performance indexes of the website which helps in delivering a better user experience for the visitors.\n  * Cookie\nAWSALB\n  * Duration\n7 days\n  * Description\nAWSALB is an application load balancer cookie set by Amazon Web Services to map the session to the target.\n\n\n  * Cookie\nacq\n  * Duration\npast\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nacq.sig\n  * Duration\npast\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nptc\n  * Duration\n2 years\n  * Description\nNo description available.\n\n\nAdvertisement\nAdvertisement cookies are used to provide visitors with customised advertisements based on the pages you visited previously and to analyse the effectiveness of the ad campaigns.\n  * Cookie\nmuc_ads\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to collect user behaviour and interaction data to optimize the website.\n\n\n  * Cookie\nguest_id_marketing\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to identify and track the website visitor.\n\n\n  * Cookie\nguest_id_ads\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to identify and track the website visitor.\n\n\n  * Cookie\npersonalization_id\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to integrate and share features for social media and also store information about how the user uses the website, for tracking and targeting.\n\n\n  * Cookie\nguest_id\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to identify and track the website visitor. It registers if a user is signed in to the Twitter platform and collects information about ad preferences.\n\n\n  * Cookie\nbcookie\n  * Duration\n1 year\n  * Description\nLinkedIn sets this cookie from LinkedIn share buttons and ad tags to recognize browser IDs.\n\n\n  * Cookie\n__Secure-ROLLOUT_TOKEN\n  * Duration\n6 months\n  * Description\nYouTube sets this cookie to manage feature rollout and experimentation. It helps Google control which new features or interface changes are shown to users as part of testing and staged rollouts, ensuring consistent experience for a given user during an experiment.\n\n\n  * Cookie\nyt.innertube::nextId\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to register a unique ID to store data on what videos from YouTube the user has seen.\n\n\n  * Cookie\nyt.innertube::requests\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to register a unique ID to store data on what videos from YouTube the user has seen.\n\n\n  * Cookie\nsession_tracker\n  * Duration\nsession\n  * Description\nThis cookie is set by the Reddit. This cookie is used to identify trusted web traffic. It also helps in adverstising on the website.\n\n\n  * Cookie\nedgebucket\n  * Duration\nsession\n  * Description\nReddit sets this cookie to save the information about a log-on Reddit user, for the purpose of advertisement recommendations and updating the content.\n\n\n  * Cookie\ndid\n  * Duration\n1 year\n  * Description\nArbor sets this cookie to show targeted ads to site visitors.This cookie expires after 2 months or 1 year.\n\n\nUncategorised\nOther uncategorised cookies are those that are being analysed and have not been classified into a category as yet.\nNo cookies to display.\nReject All Save My Preferences Accept All\nToggle Search[](https://towardsdatascience.com/)Toggle Mobile Navigation\n[](https://towardsdatascience.com/)\nPublish AI, ML & data-science insights to a global community of data professionals.\nSign in[Submit an Article](https://write.insightmediagroup.io)\n[Latest](https://towardsdatascience.com/latest/)[Editor's Picks](https://towardsdatascience.com/tag/editors-pick/)[Newsletter](https://towardsdatascience.com/tag/the-variable/)[ShipAI](https://towardsdatascience.com/shipai/)\n* * *\n[Write For TDS](https://towardsdatascience.com/submissions/)\n[LinkedIn](https://www.linkedin.com/company/towards-data-science/)[X](https://x.com/TDataScience)Toggle Search\n[Data Science](https://towardsdatascience.com/category/data-science/)\n# Learning to Rank for Product Recommendations\nThis article will go through how to use the popular XGBoost library for Learning-to-rank(LTR) problems\n[Ransaka Ravihara](https://towardsdatascience.com/author/ransakaravihara/)\nSeptember 3, 20225 min read\n![Photo by Malvestida on Unsplash](https://assets.insightmediagroup.io/media/wp-content/uploads/2022/09/00Hlw7StBsU06xvrW-scaled.jpg)\nPhoto by [Malvestida](https://unsplash.com/@malvestida?utm_source=medium&utm_medium=referral) on [Unsplash](https://unsplash.com?utm_source=medium&utm_medium=referral)\nThe most common use cases of LTR are Search Engines and Recommender Systems. The ultimate goal of ranking is to order items in a meaningful order. This article will use the popular XGBoost library for movie recommendations.\nWhen starting working on LTR, my first question was, what is the difference between traditional machine learning and ranking problems? So this is what I found. Each instance has a target class or value in traditional machine learning problems. For example, If you are working with a churn prediction problem, you have the feature set for each customer and relevant classes. Likewise, our output would be a customer id and predicted class or probability score. But in LTR, we don't have a single class or value for each instance. Instead, we have multiple items and their ground truth value per instance, and our output will be the optimal ordering of those items. For example, If we have a user's past interaction with items, Our aim is to build a model capable of predicting optimal user-item pairs.\nNow it's time to get into the coding part. For simplicity, I'll use the movielens¹ small dataset. You can download the dataset using the below link.\n> [**MovieLens Latest Datasets**](https://grouplens.org/datasets/movielens/latest/)\nLet's load the dataset and do basic preprocessing on the dataset.\nLearn this step by step with the interactive [AI and Data Scientist](https://roadmap.sh/ai-data-scientist) roadmap.\n![](https://assets.insightmediagroup.io/media/wp-content/uploads/2022/09/1RMEpw6n3Zhr1LDqw8Gmv3Q.png)\nIn this dataset, we have 100,000 ratings and 3,600 tag applications applied to 9,000 movies by 600 users.\nLet's quickly look at the rating column.\n![Review count by value](https://assets.insightmediagroup.io/media/wp-content/uploads/2022/09/1FUU-C9onw6-0kg1qR9eevw.png)\nReview count by value\n![Review count by day name](https://assets.insightmediagroup.io/media/wp-content/uploads/2022/09/15ci_Q9rTiCw86IvNQzDpqQ.png)\nReview count by day name\n![Review count by received hour](https://assets.insightmediagroup.io/media/wp-content/uploads/2022/09/1w5_d6-R3rCA22gG-pm1vIQ.png)\nReview count by received hour\n* * *\nAfter looking at the above plots, I added a time-based, day-based feature for the modeling. So, I will create user-level and item-level features. For example, for some movie \"X\", I am getting a total number of users interacted with, 5,4,3,2, and 1-star reviews received. Also, I am adding received reviews daily and received reviews after 5 PM.\nLet's split the dataset into train and test sets. I'll use the past as training, and the latest data will use to evaluate the model.\nNow it's time to create model inputs. Since the ranking model differs from traditional supervised models, we have to input additional information into the model. Now time to create the model. We will use xgboost, XGBRanker. Let's focus on it's _.fit_ method. Below is the docstring for _XGBRanker().fit()._\n> Signature: model.fit(X, y, group, sample_weight=None, eval_set=None, sample_weight_eval_set=None, eval_group=None, eval_metric=None, early_stopping_rounds=None, verbose=False, xgb_model=None, callbacks=None) Docstring: Fit the gradient boosting model\n> Parameters\n> X : array_like Feature matrix y : array_like Labels group : array_like **group size of training data** sample_weight : array_like group weights .. note:: Weights are per-group for ranking tasks In ranking task, one weight is assigned to each group (not each data point). This is because we only care about the relative ordering of data points within each group, so it doesn't make sense to assign weights to individual data points.\n* * *\nAs per the below docstring, we have to input group for both training and test samples. So the question is how to create a group array in ranking models. I saw many people who struggled to understand this group parameter.\nIn simple words, the group parameter indicates the number of interactions per user. As per the below snippet, you can see user number one has interacted with two items (11 & 12). Hence, the user 1 group size is 2. Furthermore, group length should equal the number of unique users in the dataset, and the sum of group size should equal the total number of records in the dataset. In below example _**group**_ parameter is _[2,1,4]_.\n![](https://assets.insightmediagroup.io/media/wp-content/uploads/2022/09/1ZJA1if1apPVbRsKfbjGu0Q.png)\nLet's create model inputs. We can use the below code for that.\nNow we have train and test inputs to feed into the model. It's time to train and evaluate the model. Before doing that, I have a few terminologies to explain for the article's completeness.\nWhen model building, measuring the quality of the predictions is essential. What are the available measurements for evaluating recommendation models? There are few, but the most common measures are [[Normalized Discounted Cumulative Gain (NDCG)](http://en.wikipedia.org/wiki/NDCG)](http://en.wikipedia.org/wiki/NDCG) and [Mean Average Precision (MAP)](http://en.wikipedia.org/wiki/Mean_average_precision#Mean_average_precision). Here I will use NDCG as an evaluation metric. NDCG is the enhanced version of CG (Cumulative Gain). In CG, recommending an order does not matter. If your results contain relevant items in any order, this will give you a higher value, indicating our predictions are good. But in the real world, it's not the case. We should prioritize relevant items when recommending. To achieve this, we should penalize when low relevance items appear earlier in the results. That is what DCG does. But still, DCG suffers when different users have a different set of item/interaction counts. That's where Normalized Discounted Cumulative Gain (NDCG) comes into play. It will bring normalization to the DCG metric.\nNow we can move to the model part.\nNow we can generate some predictions.\nHere are some generated predictions.\n![](https://assets.insightmediagroup.io/media/wp-content/uploads/2022/09/14H2IqDzkA5-GQR-VZEAZHg.png)\nIt's always nice to evaluate the coverage of your recommender model. Using the coverage metric, you can check the percentage of training products in the test set. The more coverage better the model. In some cases model tries to predict popular merchants to maximize NDCG and MAP@k. I had this issue when I was working on [starpoints ](https://play.google.com/store/apps/details?id=com.atlinkcom.starpointapp&hl=en&gl=US)product recommendations. When we have doubts about our evaluation metric, we can quickly check the coverage of our model. In this model, I got around 2% coverage. Indicates our model should improve further.\nAdditionally, we can plot feature importance as follows.\n![feature importance for XGBRanker](https://assets.insightmediagroup.io/media/wp-content/uploads/2022/09/1iZjarbWIPuck-G2K8p0ZgA.png)\nfeature importance for XGBRanker\n## Conclusion\nIn this article, we went through the basics of learning-to-rank problems, how we can model rank problems, and a few tips related to evaluating recommendation models. Although this article shows how we can use xgboost for product ranking problems, we can also use this approach for other ranking problems.\n_**References**_\n_1 [Grouplence ] F. Maxwell Harper and Joseph A. Konstan. 2015. The MovieLens Datasets: History and Context. ACM Transactions on Interactive Intelligent Systems (TiiS) 5, 4: 19:1–19:19._[_https://doi.org/10.1145/2827872_](https://doi.org/10.1145/2827872)\nThanks for reading. You can access the colab notebook using [this](https://colab.research.google.com/drive/1pyhxI2skMUVsVVwZQ2uX2Pse8Y_NZH2N?usp=sharing) link.\nConnect with me on [_LinkedIn_](http://www.linkedin.com/in/ransaka).\n## Register Now to Continue Reading\n### Unlock Towards Data Science with a Free Account\nAll articles on Towards Data Science are available to registered users. Create a free account today to access this article and thousands more.\nRegister for freeSign in to your account\n* * *\n![](https://assets.insightmediagroup.io/media/1787657265628_qm714e.jpeg)\nWritten By\n## [Ransaka Ravihara](https://towardsdatascience.com/author/ransakaravihara/)\n[See all from Ransaka Ravihara](https://towardsdatascience.com/author/ransakaravihara/)\n[Data Science](https://towardsdatascience.com/tag/data-science/)[Hands On Tutorials](https://towardsdatascience.com/tag/hands-on-tutorials/)[Python](https://towardsdatascience.com/tag/python/)[Recommendation System](https://towardsdatascience.com/tag/recommendation-system/)[Recommendations](https://towardsdatascience.com/tag/recommendations/)\nShare This Article\n  * [](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Ftowardsdatascience.com%2Flearning-to-rank-for-product-recommendations-a113221ad8a7%2F&title=Learning%20to%20Rank%20for%20Product%20Recommendations)\n  * [](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Ftowardsdatascience.com%2Flearning-to-rank-for-product-recommendations-a113221ad8a7%2F&title=Learning%20to%20Rank%20for%20Product%20Recommendations)\n  * [](https://x.com/share?url=https%3A%2F%2Ftowardsdatascience.com%2Flearning-to-rank-for-product-recommendations-a113221ad8a7%2F&text=Learning%20to%20Rank%20for%20Product%20Recommendations)\n\n\nTowards Data Science is a community publication. Submit your insights to reach our global audience and earn through the TDS Author Payment Program.\n[Write for TDS](https://towardsdatascience.com/submissions/)\n## Related Articles\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2020/12/0gc_iYRaetVp4HFft-scaled.jpg)](https://towardsdatascience.com/pulling-an-all-nighter-e27b18ad96c7/)\n## [Pulling an all nighter](https://towardsdatascience.com/pulling-an-all-nighter-e27b18ad96c7/)\n[Deep Learning](https://towardsdatascience.com/category/artificial-intelligence/deep-learning/)\nConfiguring GPU libraries on Ubuntu 20.4 LTS\n[David Moore](https://towardsdatascience.com/author/cognitivedave/)\nDecember 31, 20206 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2023/12/1Qjs6CAlXbpBKlCiFFYxscw.jpeg)](https://towardsdatascience.com/a-guide-to-21-feature-importance-methods-and-packages-in-machine-learning-with-code-85a841f8b319/)\n## [A Guide to 21 Feature Importance Methods and Packages in Machine Learning (with Code)](https://towardsdatascience.com/a-guide-to-21-feature-importance-methods-and-packages-in-machine-learning-with-code-85a841f8b319/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nFrom the OmniXAI, Shapash, and Dalex interpretability packages to the Boruta, Relief, and Random Forest feature selection algorithms\n[Theophano Mitsa](https://towardsdatascience.com/author/theomitsa/)\nDecember 19, 202320 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2026/05/a-c-JNwba6cv4e0-unsplash.jpg)](https://towardsdatascience.com/explaining-lineage-in-dax/)\n## [Explaining Lineage in DAX](https://towardsdatascience.com/explaining-lineage-in-dax/)\n[Power BI](https://towardsdatascience.com/category/data-analysis/power-bi/)\nOne of the most important concepts in DAX is lineage. It’s about the information on where something comes from. Let’s see what it is and how we can manipulate it.\n[Salvatore Cagliari](https://towardsdatascience.com/author/salvatorecagliari/)\nMay 29, 20269 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2021/11/1qfTFv2FuGoWbiEmqeSgg3A.png)](https://towardsdatascience.com/a-hidden-gem-df-select-dtypes-a660db0e8609/)\n## [A hidden gem: df.select_dtypes()](https://towardsdatascience.com/a-hidden-gem-df-select-dtypes-a660db0e8609/)\n[Data Science](https://towardsdatascience.com/category/data-science/)\nA micro-post about a Pandas function from 2014 that had been flying under the radar for me.\n[Patty C](https://towardsdatascience.com/author/patrickcoffey/)\nNovember 12, 20212 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2023/03/1CFspMVl04e80mRYNK3Nohw-scaled.jpeg)](https://towardsdatascience.com/vim-tutorial-edit-text-like-a-pro-ea13e45010f5/)\n## [VIM Tutorial - Edit Text Like a Pro](https://towardsdatascience.com/vim-tutorial-edit-text-like-a-pro-ea13e45010f5/)\n[Artificial Intelligence](https://towardsdatascience.com/category/artificial-intelligence/)\nAn easy-to-follow tutorial for Vim text editor\n[Farzad Nobar](https://towardsdatascience.com/author/fmnobar/)\nMarch 6, 202311 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2024/04/0epRv9ArHlvR-Awz8-scaled.jpg)](https://towardsdatascience.com/transform-data-with-hyperbolic-sine-e39e9275b6ba/)\n## [Transform Data with Hyperbolic Sine](https://towardsdatascience.com/transform-data-with-hyperbolic-sine-e39e9275b6ba/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nWhy handling negative values should be a cinch\n[David Kyle](https://towardsdatascience.com/author/david.kyle_13073/)\nApril 29, 20248 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2020/08/1MKVmbPOUXhyZMe446deriA-scaled.jpeg)](https://towardsdatascience.com/first-day-of-social-data-science-beedc2174232/)\n## [First Day of Social Data Science](https://towardsdatascience.com/first-day-of-social-data-science-beedc2174232/)\n[Data Science](https://towardsdatascience.com/category/data-science/)\nThe inaugural cohort of the University of Copenhagen's MSc of Social Data Science (SODAS)\n[Alex Moltzau](https://towardsdatascience.com/author/alexmoltzau/)\nAugust 31, 20206 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2020/12/1Xmh8h51REA1QGDkx9LE1iw.jpeg)](https://towardsdatascience.com/5-bigquery-sql-performance-tips-for-modern-data-scientists-f880b79cfa71/)\n## [5 Bigquery SQL performance tips for modern data scientists](https://towardsdatascience.com/5-bigquery-sql-performance-tips-for-modern-data-scientists-f880b79cfa71/)\n[Data Science](https://towardsdatascience.com/category/data-science/)\nSQL tuning tips and advice to help reduce BigQuery costs. Start 2021 off on the right foot!\n[James Green](https://towardsdatascience.com/author/google-cloud-data/)\nDecember 12, 20208 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2019/06/1k0v39powS7PjJ7Qv_NPTjw.png)](https://towardsdatascience.com/lessons-from-a-real-machine-learning-project-part-2-the-traps-of-data-exploration-e0061ace84aa/)\n## [Lessons from a real Machine Learning project, part 2: the traps of data exploration](https://towardsdatascience.com/lessons-from-a-real-machine-learning-project-part-2-the-traps-of-data-exploration-e0061ace84aa/)\n[Artificial Intelligence](https://towardsdatascience.com/category/artificial-intelligence/)\nHow to fall into the pitfalls of data exploration and get away\n[Emanuele Fabbiani](https://towardsdatascience.com/author/donlelef/)\nJune 4, 20194 min read\n\n\n  * [YouTube](https://www.youtube.com/c/TowardsDataScience)\n  * [X](https://x.com/TDataScience)\n  * [LinkedIn](https://www.linkedin.com/company/towards-data-science/)\n  * [Threads](https://www.threads.net/@towardsdatascience)\n  * [Bluesky](https://bsky.app/profile/towardsdatascience.com)\n\n\n[](https://towardsdatascience.com/)\nYour home for data science and AI. The world's leading publication for data science, data analytics, data engineering, machine learning, and artificial intelligence professionals.\nSubscribe to Our Newsletter[Write For TDS](https://towardsdatascience.com/submissions/)•[About](https://towardsdatascience.com/about-towards-data-science-d691af11cc2f/)•[Advertise](https://contact.towardsdatascience.com/advertise-with-towards-data-science)•[Privacy Policy](https://towardsdatascience.com/privacy-policy/)•[Terms of Use](https://towardsdatascience.com/website-terms-of-use/)\n© Insight Media Group, LLC 2026•[The New Stack](https://thenewstack.io)•[roadmap.sh](https://roadmap.sh)•[Creator Network](https://insightmediagroup.io/creator-network)\n####  Recommended Articles \nClose\n  * [ ![](https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607631/image?etag=1781543525510&width=500&height=500) Critical Mistakes Companies Make When Integrating AI/ML into Their Processes ](https://towardsdatascience.com/critical-mistakes-companies-make-when-integrating-ai-ml-into-their-processes/ \"Critical Mistakes Companies Make When Integrating AI/ML into Their Processes\")\n  * [ ![](https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607686/image?etag=1782161464448&width=500&height=500) How Relevance Models Foreshadowed Transformers for NLP ](https://towardsdatascience.com/how-relevance-models-foreshadowed-transformers-for-nlp/ \"How Relevance Models Foreshadowed Transformers for NLP\")\n  * [ ![](https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607639/image?etag=1781250125848&width=500&height=500) Javascript Fatigue: HTMX Is All You Need to Build ChatGPT — Part 1 ](https://towardsdatascience.com/javascript-fatigue-you-dont-need-js-to-build-chatgpt/ \"Javascript Fatigue: HTMX Is All You Need to Build ChatGPT — Part 1\")\n  * [ ![](https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607930/image?etag=1782124566054&width=500&height=500) The Subset Sum Problem Solved in Linear Time for Dense Enough Inputs ](https://towardsdatascience.com/subset-sum-problem-solved-in-linear-time-for-dense-enough-inputs/ \"The Subset Sum Problem Solved in Linear Time for Dense Enough Inputs\")\n\n\n",
  "metadata": {
    "title": "Learning to Rank for Product Recommendations | Towards Data Science",
    "description": "This article will go through how to use the popular XGBoost library for Learning-to-rank(LTR) problems",
    "keywords": null,
    "author": "Ransaka Ravihara",
    "og:locale": "en_US",
    "og:type": "article",
    "og:title": "Learning to Rank for Product Recommendations",
    "og:description": "This article will go through how to use the popular XGBoost library for Learning-to-rank(LTR) problems",
    "og:url": "https://towardsdatascience.com/learning-to-rank-for-product-recommendations-a113221ad8a7/",
    "og:site_name": "Towards Data Science",
    "og:image": "https://assets.insightmediagroup.io/media/wp-content/uploads/2022/09/00Hlw7StBsU06xvrW-scaled.jpg",
    "og:image:width": "1707",
    "og:image:height": "2560",
    "og:image:type": "image/jpeg",
    "twitter:card": "summary_large_image",
    "twitter:site": "@TDataScience",
    "twitter:creator": "@TDataScience",
    "twitter:label1": "Written by",
    "twitter:data1": "Ransaka Ravihara",
    "twitter:label2": "Est. reading time",
    "twitter:data2": "5 min read",
    "article:published_time": "2022-09-03T02:52:45.000Z",
    "article:modified_time": "2022-09-03T02:52:45.000Z",
    "article:author": "https://towardsdatascience.com/author/ransakaravihara/"
  },
  "paywall": {
    "listed_paid": true,
    "detected": false,
    "marker": "",
    "public_only": true,
    "policy": "付费/会员内容只保留页面公开可见部分，不绕过付费墙"
  },
  "crawl": {
    "success": true,
    "status_code": 200,
    "error": ""
  },
  "code_blocks": [],
  "images": [
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2022/09/00Hlw7StBsU06xvrW-scaled.jpg",
      "alt": "Photo by Malvestida on Unsplash",
      "local_path": "attachments/37a77accefed/images/000.jpg",
      "bytes": 565095,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2022/09/1RMEpw6n3Zhr1LDqw8Gmv3Q.png",
      "alt": "",
      "local_path": "attachments/37a77accefed/images/001.png",
      "bytes": 15352,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2022/09/1FUU-C9onw6-0kg1qR9eevw.png",
      "alt": "Review count by value",
      "local_path": "attachments/37a77accefed/images/002.png",
      "bytes": 5170,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2022/09/15ci_Q9rTiCw86IvNQzDpqQ.png",
      "alt": "Review count by day name",
      "local_path": "attachments/37a77accefed/images/003.png",
      "bytes": 10296,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2022/09/1w5_d6-R3rCA22gG-pm1vIQ.png",
      "alt": "Review count by received hour",
      "local_path": "attachments/37a77accefed/images/004.png",
      "bytes": 7951,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2022/09/1iZjarbWIPuck-G2K8p0ZgA.png",
      "alt": "feature importance for XGBRanker",
      "local_path": "attachments/37a77accefed/images/005.png",
      "bytes": 28770,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2020/12/0gc_iYRaetVp4HFft-scaled.jpg",
      "alt": "",
      "local_path": "attachments/37a77accefed/images/006.jpg",
      "bytes": 341936,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2023/12/1Qjs6CAlXbpBKlCiFFYxscw.jpeg",
      "alt": "",
      "local_path": "attachments/37a77accefed/images/007.jpeg",
      "bytes": 191004,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2026/05/a-c-JNwba6cv4e0-unsplash.jpg",
      "alt": "",
      "local_path": "attachments/37a77accefed/images/008.jpg",
      "bytes": 73243,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2021/11/1qfTFv2FuGoWbiEmqeSgg3A.png",
      "alt": "",
      "local_path": "attachments/37a77accefed/images/009.png",
      "bytes": 51736,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2023/03/1CFspMVl04e80mRYNK3Nohw-scaled.jpeg",
      "alt": "",
      "local_path": "attachments/37a77accefed/images/010.jpeg",
      "bytes": 1144356,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2024/04/0epRv9ArHlvR-Awz8-scaled.jpg",
      "alt": "",
      "local_path": "attachments/37a77accefed/images/011.jpg",
      "bytes": 185692,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2020/08/1MKVmbPOUXhyZMe446deriA-scaled.jpeg",
      "alt": "",
      "local_path": "attachments/37a77accefed/images/012.jpeg",
      "bytes": 283501,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2020/12/1Xmh8h51REA1QGDkx9LE1iw.jpeg",
      "alt": "",
      "local_path": "attachments/37a77accefed/images/013.jpeg",
      "bytes": 41673,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2019/06/1k0v39powS7PjJ7Qv_NPTjw.png",
      "alt": "",
      "local_path": "attachments/37a77accefed/images/014.png",
      "bytes": 65537,
      "downloaded": true
    }
  ],
  "audio": [],
  "videos": [
    {
      "src": "https://www.youtube.com/c/TowardsDataScience",
      "quality": "unavailable",
      "local_path": "",
      "note": "无1080p且无720p，未交付更低清晰度"
    }
  ],
  "links": [
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/latest/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/editors-pick/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/the-variable/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/shipai/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/submissions/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/category/data-science/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/author/ransakaravihara/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/data-science/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/hands-on-tutorials/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/python/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/recommendation-system/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/recommendations/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/pulling-an-all-nighter-e27b18ad96c7/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/category/artificial-intelligence/deep-learning/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/author/cognitivedave/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/a-guide-to-21-feature-importance-methods-and-packages-in-machine-learning-with-code-85a841f8b319/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/category/artificial-intelligence/machine-learning/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/author/theomitsa/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/explaining-lineage-in-dax/"
    },
    {
      "type": "external",
      "href": "https://write.insightmediagroup.io"
    },
    {
      "type": "external",
      "href": "https://www.linkedin.com/company/towards-data-science/"
    },
    {
      "type": "external",
      "href": "https://x.com/TDataScience"
    },
    {
      "type": "external",
      "href": "https://unsplash.com/@malvestida"
    },
    {
      "type": "external",
      "href": "https://unsplash.com"
    },
    {
      "type": "external",
      "href": "https://grouplens.org/datasets/movielens/latest/"
    },
    {
      "type": "external",
      "href": "https://roadmap.sh/ai-data-scientist"
    },
    {
      "type": "external",
      "href": "http://en.wikipedia.org/wiki/NDCG"
    },
    {
      "type": "external",
      "href": "http://en.wikipedia.org/wiki/Mean_average_precision"
    },
    {
      "type": "external",
      "href": "https://play.google.com/store/apps/details?gl=US&hl=en&id=com.atlinkcom.starpointapp"
    },
    {
      "type": "external",
      "href": "https://doi.org/10.1145/2827872"
    },
    {
      "type": "external",
      "href": "https://colab.research.google.com/drive/1pyhxI2skMUVsVVwZQ2uX2Pse8Y_NZH2N?usp=sharing"
    },
    {
      "type": "external",
      "href": "http://www.linkedin.com/in/ransaka"
    },
    {
      "type": "external",
      "href": "https://www.facebook.com/sharer/sharer.php?title=Learning+to+Rank+for+Product+Recommendations&u=https%3A%2F%2Ftowardsdatascience.com%2Flearning-to-rank-for-product-recommendations-a113221ad8a7%2F"
    },
    {
      "type": "external",
      "href": "https://www.linkedin.com/shareArticle?mini=true&title=Learning+to+Rank+for+Product+Recommendations&url=https%3A%2F%2Ftowardsdatascience.com%2Flearning-to-rank-for-product-recommendations-a113221ad8a7%2F"
    },
    {
      "type": "external",
      "href": "https://x.com/share?text=Learning+to+Rank+for+Product+Recommendations&url=https%3A%2F%2Ftowardsdatascience.com%2Flearning-to-rank-for-product-recommendations-a113221ad8a7%2F"
    },
    {
      "type": "external",
      "href": "https://www.youtube.com/c/TowardsDataScience"
    },
    {
      "type": "external",
      "href": "https://www.threads.net/@towardsdatascience"
    },
    {
      "type": "external",
      "href": "https://bsky.app/profile/towardsdatascience.com"
    },
    {
      "type": "external",
      "href": "https://thenewstack.io"
    }
  ],
  "repair_version": 2,
  "repaired_at": "2026-10-14T11:11:49Z",
  "source_url": "https://towardsdatascience.com/learning-to-rank-for-product-recommendations-a113221ad8a7/",
  "delivery_status": "excluded_paid",
  "discovery_status": "excluded_paid",
  "missing_reason": "按原约定排除付费/会员全文"
}