Chapter 102
📝Draft

Contextual Bandits

Personalized decisions based on context features

Prerequisites:

What You'll Learn

  • Understand how contextual bandits extend multi-armed bandits with features
  • Formalize the contextual bandit problem mathematically
  • Implement LinUCB for linear reward models
  • Recognize real-world applications in recommendations, advertising, and personalization
  • Understand the bridge from bandits to full reinforcement learning

A news website needs to decide which headline to show each visitor. But here’s the catch: different people like different things. A sports fan wants game scores; a tech enthusiast wants startup news.

This isn’t just about finding the best arm—it’s about finding the best arm for each person. Welcome to contextual bandits.

From One-Size-Fits-All to Personalization

In multi-armed bandits, we sought a single best action. But many real problems have context—features that should inform our decision:

  • User profile: Age, location, browsing history
  • Time of day: Morning news vs evening entertainment
  • Device type: Mobile users want shorter content

Contextual bandits learn to map these features to actions, personalizing decisions while still exploring efficiently.

ℹ️Note

Contextual bandits are the workhorse behind modern recommendation systems, online advertising, and personalized medicine. They’re simpler than full RL but more powerful than basic bandits.

Chapter Overview

The Key Insight

📖Contextual Bandit

A sequential decision problem where the agent observes context (features) before choosing an action, and the expected reward depends on both the context and the chosen action.

Contextual bandits bridge the gap between:

  • Simple bandits: One best arm for everyone
  • Full RL: Sequential decisions that change the environment

By conditioning on context, we personalize without needing the full complexity of states and transitions.

Prerequisites

This chapter builds on:


Key Takeaways

  1. Context allows personalization
    Instead of one best arm for everyone, the agent learns a mapping from features to actions—different users get different recommendations.
  2. LinUCB extends UCB to linear reward models
    Confidence ellipsoids over the weight vector play the role that per-arm confidence intervals played in plain UCB.
  3. Context is not state
    Your action does not change the next context you see. That independence is exactly what keeps contextual bandits simpler than full RL.
  4. Contextual bandits power real systems
    News recommendation, online advertising, and adaptive clinical trials all run on these ideas.
  5. When actions affect future context, you need full RL
    Once today’s recommendation changes tomorrow’s user, you are in MDP territory—the subject of the next chapters.

Check Your Understanding

Check your understanding
1. What distinguishes context (in a contextual bandit) from state (in full RL)?
2. How does LinUCB decide which arm to pull for a given context?
3. A news site’s recommender changes what a user reads today, which changes what that same user wants tomorrow. What does this imply?
4. Why not just learn each user segment’s best arm with a separate multi-armed bandit?
Next ChapterMonte Carlo Methods