Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Online ml River Bandit Datasets NewsArticles

From Leeroopedia


Knowledge Sources
Domains Online_Learning, Multi_Armed_Bandits, Contextual_Bandits, Personalization
Last Updated 2026-02-08 16:00 GMT

Overview

A contextual bandit dataset for news article personalization with 10,000 observations, 10 arms, binary rewards, and 100 context features.

Description

NewsArticles is a personalization dataset designed for contextual bandit problems. It contains 10,000 user interactions with news articles, where each observation includes 100 contextual features representing user preferences or article characteristics. There are 10 possible arms (articles) to choose from, and the reward is binary (clicked or not clicked). This dataset is commonly used for evaluating contextual bandit algorithms in recommendation scenarios.

Usage

Use this dataset when evaluating contextual bandit algorithms, particularly for personalization and recommendation tasks. It's suitable for testing algorithms like LinUCB that can leverage contextual information to improve arm selection decisions.

Code Reference

Source Location

Signature

class NewsArticles(datasets.base.RemoteDataset, BanditDataset):
    def __init__(self):
        ...

    @property
    def arms(self) -> list:
        return list(range(1, 11, 1))

Import

from river import bandit

I/O Contract

Property Type Value
n_features int 100
n_samples int 10,000
arms list[int] [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
reward type bool Binary (clicked/not clicked)

Usage Examples

from river import bandit

dataset = bandit.datasets.NewsArticles()

# Get the first observation
context, arm, reward = next(iter(dataset))

print(len(context))  # 100
print(arm, reward)   # (2, False)

# Use with a contextual bandit policy
policy = bandit.LinUCBDisjoint(alpha=1.0, seed=42)

for context, arm, reward in dataset:
    # In practice, you would pull an arm based on the context
    # and only observe the reward for the pulled arm
    policy.update(arm, context, reward)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment