Explaining Reinforcement Learning with Shapley Values

Daniel Beechey, Thomas M. S. Smith, Özgür Şimşek

Abstract

For reinforcement learning systems to be widely adopted, their users must understand and trust them. We present a theoretical analysis of explaining reinforcement learning using Shapley values, following a principled approach from game theory for identifying the contribution of individual players to the outcome of a cooperative game. We call this general framework Shapley Values for Explaining Reinforcement Learning (SVERL). Our analysis exposes the limitations of earlier uses of Shapley values in reinforcement learning. We then develop an approach that uses Shapley values to explain agent performance. In a variety of domains, SVERL produces meaningful explanations that match and supplement human intuition.

Introduction

Reinforcement Learning (RL) agents are increasingly deployed in complex environments, yet they often remain "black boxes," making it difficult for human operators to trust their decisions. While Shapley values—a concept from cooperative game theory—have been successfully used in supervised learning to attribute model predictions to input features, applying them to RL is not straightforward. Existing methods often treat RL models as static calculators, ignoring the "closed-loop" nature of the environment where features influence behavior, not just predictions.

This paper introduces SVERL (Shapley Values for Explaining Reinforcement Learning), a framework designed to explain why an agent succeeds rather than just what it predicts. By identifying which state features drive an agent's actual performance (expected return), SVERL provides explanations that align more closely with human intuition.

The SVERL Framework

The core innovation of SVERL is the definition of a "characteristic value function" based on the expected return of the agent. We propose SVERL-P (SVERL-Performance), which evaluates feature importance through two lenses:

  1. Local SVERL-P: Explains feature importance in a specific state by calculating how the expected return changes if the agent makes a decision without seeing certain features.
  2. Global SVERL-P: Aggregates these contributions across the environment to identify features critical for overall success.

To handle the dynamic nature of RL, SVERL explicitly considers Policy Adaptation. Unlike previous work, it models how an agent’s policy $\pi$ would change into a marginalized policy $\pi_C$ when features are missing. Furthermore, it utilizes On-Manifold Sampling via the limiting state occupancy distribution to ensure that "removed" features are replaced with values that are contextually relevant to the agent's typical behavior.

Experimental Evaluation and Results

We evaluated SVERL across several benchmarks, including Gridworlds, Tic-Tac-Toe, the Taxi domain, and Minesweeper.

Intuition Matching in Gridworlds

In Gridworld-A, where the optimal action is always "North" regardless of the agent's coordinates, a feature's contribution to performance should be zero. Traditional Shapley values applied to the $Q$-function incorrectly assign high importance to coordinates because they help predict the value, even if they don't improve performance. SVERL-P correctly identifies these as having zero contribution.

Figure 5: Comparison of traditional Shapley values vs. SVERL-P in Gridworld-A. SVERL-P correctly assigns zero importance to features that do not impact performance, whereas traditional methods fail to do so.

Critical Information in Tic-Tac-Toe

In games like Tic-Tac-Toe, SVERL-P highlights squares that are "bottlenecks" for success. While traditional value-based explanations might show a uniform distribution of importance, SVERL-P pinpoints the specific moves that are most critical for the agent to maintain its winning or drawing strategy against a Minimax opponent.

Figure 6: Heatmap comparing Shapley values applied to the value function (V*) versus SVERL-P in Tic-Tac-Toe. SVERL-P provides a more nuanced view of which board positions are critical for the agent's performance.

Insights from Complex Domains

In the Taxi domain, SVERL-P revealed a "Dangerous Knowledge" effect: seeing the destination before picking up a passenger actually decreased performance by causing the agent to navigate prematurely toward the goal. In Minesweeper, a high-dimensional environment, SVERL-P successfully identified critical squares that, if hidden, would make the game impossible to solve, even if other squares provided more raw information.

Conclusion and Future Work

SVERL represents a shift from explaining model math to explaining agent success. By focusing on performance, it avoids the pitfalls of treating RL agents as static predictors. While calculating exact Shapley values remains computationally expensive (NP-hard), the approximation methods provided in this work demonstrate that SVERL can produce meaningful, intuitive explanations. Future research will focus on scaling these methods to massive environments and conducting human subject studies to validate the utility of SVERL in building user trust.

Summary updated

BibTeX
@inproceedings{beechey2023explaining,
  author = {Daniel Beechey and Thomas M. S. Smith and Özgür Şimşek},
  title = {{Explaining Reinforcement Learning with Shapley Values}},
  booktitle = {International Conference on Machine Learning},
  year = {2023},
  url = {https://openreview.net/forum?id=R1blujRwj1},
}
Figure