Mab2Rec: Multi-Armed Bandits Recommender
June 24, 2026 ยท View on GitHub
Mab2Rec: Multi-Armed Bandits Recommender
Mab2Rec (AAAI'24) is a Python framework for building bandit-based recommendation algorithms. It supports context-free, parametric and non-parametric contextual bandit models. It is designed to enable a modular, interoperable, and scalable AI ecosystem for recommender systems built around industry-strength, reusable, open-source software. The strategy behind the core components is detailed in Open-Source AI at Scale: Establishing an Enterprise AI Strategy through Modular Frameworks (AI Magazine'25).
Please see the Mab2Rec Homepage for more details fidelity.github.io/mab2rec.
Usage Patterns
Mab2Rec supports prototyping with a single bandit algorithm or benchmarking with multiple bandit algorithms. If you are new user, the best place to start is to experiment with multiple bandits using the tutorial notebooks.
Quick Start
Single Recommender
# Example of how to train a single recommender to generate top-4 recommendations
# Import
from mab2rec import BanditRecommender, LearningPolicy
from mab2rec.pipeline import train, score
# LinGreedy recommender to select top-4 items with 10% random exploration
rec = BanditRecommender(LearningPolicy.LinGreedy(epsilon=0.1), top_k=4)
# Train on (user, item, response) interactions in train data using user features
train(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 items
df = 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 recommendations
from mab2rec import BanditRecommender, LearningPolicy
from mab2rec.pipeline import benchmark
from jurity.recommenders import BinaryRecoMetrics, 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 columns
metric_params = {'click_column': 'score', 'user_id_column': 'user_id', 'item_id_column':'item_id'}
# Performance metrics for benchmarking (many more available)
metrics = []
for top_k in [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 algorithm
reco_to_results, reco_to_metrics = benchmark(recommenders,
metrics=metrics,
train_data="data/data_train.csv",
cv=5,
user_features="data/features_user.csv")
Usage Examples
We provide extensive tutorials in the notebooks folder 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.
Installation
Mab2Rec requires Python 3.8+ and can be installed from PyPI using pip install mab2rec or by building from source as shown in installation instructions.
Citation
If you use Mab2Rec in a publication, please cite it as:
@inproceedings{DBLP:conf/aaai/KadiogluK24,
author = {Serdar Kadioglu and Bernard Kleynhans},
title = {Building Higher-Order Abstractions from the Components of Recommender Systems},
booktitle = {Thirty-Eighth {AAAI} Conference on Artificial Intelligence, {AAAI} 2024, Thirty-Sixth Conference on Innovative Applications of Artificial Intelligence, {IAAI} 2024, Fourteenth Symposium on Educational Advances in Artificial Intelligence, {EAAI} 2014, February 20-27, 2024, Vancouver, Canada},
pages = {22998--23004},
publisher = {{AAAI} Press},
year = {2024},
url = {https://doi.org/10.1609/aaai.v38i21.30341},
doi = {10.1609/AAAI.V38I21.30341}
}
Support
Please submit bug reports and feature requests as Issues.
License
Mab2Rec is licensed under the Apache License 2.0.