Package: mab2rec
Mab2Rec: Multi-Armed Bandits RecommenderMab2Rec is a Python library for building bandit-based recommendation algorithms. It supportscontext-free,parametricandnon-parametriccontextualbandit models powered byMABWiserand fairness and recommenders evaluations powered byJurity.
It supportsall bandit policies available in MABWiser. The library is designed with rapid experimentation in mind, follows thePEP-8 standardsand is tested heavily.Mab2Rec is built on top of several other open-source software developed at the AI Center at Fidelity:MABWiserto create multi-armed bandit recommendation algorithms (IJAIT'21,ICTAI'19).TextWiserto create item representations via text featurization (AAAI'21).Selectiveto create user representations via feature selection (CPAIOR'21,DSO@IJCAI'21).Seq2Patto create users representations via sequential pattern mining (AAAI'22,KDF@AAAI'22,Frontiers'22)Jurityto evaluate recommendations including fairness metrics (ICMLA'21).An introduction tocontent- and context-awarerecommender systems and an overview of the building blocks of the library is presented atAll Things Open 2021. There is also a correspondingblogpostas a starting point for practioners to build and deploy bandit-based recommenders using Mab2Rec.Documentation is available atfidelity.github.io/mab2rec.Usage PatternsMab2Rec supports prototyping with asinglebandit algorithm or benchmarking withmultiplebandit algorithms.
If you are new user, the best place to start is to experiment with multiple bandits using thetutorial notebooks.Quick StartSingle Recommender# Example of how to train an singler recommender to generate top-4 recommendations# Importfrommab2recimportBanditRecommender,LearningPolicyfrommab2rec.pipelineimporttrain,score# LinGreedy recommender to select top-4 items with 10% random explorationrec=BanditRecommender(LearningPolicy.LinGreedy(epsilon=0.1),top_k=4)# Train on (user, item, response) interactions in train data using user featurestrain(rec,data='data/data_train.csv',user_features='data/features_user.csv')# Score recommendations for users in test data. The output df holds# user_id, item_id, score columns for every test user for top-k itemsdf=score(rec,data='data/data_test.csv',user_features='data/features_user.csv')Multiple Recommenders# Example of how to benchmark multiple recommenders to generate top-4 recommendationsfrommab2recimportBanditRecommender,LearningPolicyfrommab2rec.pipelineimportbenchmarkfromjurity.recommendersimportBinaryRecoMetrics,RankingRecoMetrics# Recommenders (many more available)recommenders={"Random":BanditRecommender(LearningPolicy.Random()),"Popularity":BanditRecommender(LearningPolicy.Popularity()),"LinGreedy":BanditRecommender(LearningPolicy.LinGreedy(epsilon=0.1))}# Column names for the response, user, and item id columnsmetric_params={'click_column':'score','user_id_column':'user_id','item_id_column':'item_id'}# Performance metrics for benchmarking (many more available)metrics=[]fortop_kin[3,5,10]:metrics.append(BinaryRecoMetrics.CTR(**metric_params,k=top_k))metrics.append(RankingRecoMetrics.NDCG(**metric_params,k=top_k))# Benchmarking with a collection of recommenders and metrics# This returns two dictionaries;# reco_to_results: recommendations for each algorithm on cross-validation data# reco_to_metrics: evaluation metrics for each algorithmreco_to_results,reco_to_metrics=benchmark(recommenders,metrics=metrics,train_data="data/data_train.csv",cv=5,user_features="data/features_user.csv")Usage ExamplesWe provide an extensive tutorial in thenotebooksfolder with guidelines on building recommenders, performing model selection, and evaluating performance.Data Overview:Overview of data required to train recommender.Feature Engineering:Creating user and item features from structured, unstructured, and sequential data.Model Selection:Model selection by benchmarking recommenders using cross-validation.Evaluation:Benchmarking of selected recommenders and baselines on test data with detailed evaluation.Advanced:Demonstration of advanced functionality such as persistency, eligibility, item availability, and memory efficiency.InstallationMab2Rec requiresPython 3.8+and can be installed from PyPI usingpip install mab2recor by building from source as shown ininstallation instructions.SupportPlease submit bug reports and feature requests asIssues.LicenseMab2Rec is licensed under theApache License 2.0.