GithubHelp home page GithubHelp logo

iancovert / shapley-regression Goto Github PK

View Code? Open in Web Editor NEW
58.0 6.0 14.0 724 KB

For calculating Shapley values via linear regression.

License: MIT License

Python 100.00%
shapley explainability interpretability game-theory

shapley-regression's Introduction

Shapley Regression

This repository implements a regression-based approach to estimating Shapley values. Although the code can be used with any cooperative game, our focus is model explanation methods such SHAP, SAGE, and Shapley Effects, which are the Shapley values of several specific cooperative games. The methods provided here were developed in this paper.

Because approximations are essential in most practical Shapley value applications, we provide an estimation approach with the following convenient features:

  1. Convergence detection: the estimator stops automatically when it is approximately converged, so you don't need to specify the number of samples.

  2. Convergence forecasting: for use cases that take a long time to run, our implementation forecasts the amount of time required to reach convergence (displayed with a progress bar).

  3. Uncertainty estimation: Shapley values are often estimated rather than calculated exactly, and our method provides confidence intervals for the results.

Usage

To use the code, clone this repository and install the package into your Python environment:

pip install .

Next, to run the code you only need to do two things: 1) specify a cooperative game, and 2) run the Shapley value estimator. For example, you can calculate SHAP values as follows:

from shapreg import removal, games, shapley

# Get data
x, y = ...
feature_names = ...

# Get model (a callable object)
model = ...

# Set up the cooperative game (SHAP)
imputer = removal.MarginalExtension(x[:128], model)
game = games.PredictionGame(imputer, x[0])

# Estimate Shapley values
values = shapley.ShapleyRegression(game)

For examples, see the following notebooks:

  • Census: shows how to explain individual predictions (SHAP)
  • Credit: shows how to explain the model's loss (SAGE)
  • Bank: shows how to explain the model's global sensitivity (Shapley Effects)
  • Consistency: verifies that our different estimators return the same results
  • Calibration: verifies the accuracy of our uncertainty estimates

Authors

References

Ian Covert and Su-In Lee. "Improving KernelSHAP: Practical Shapley Value Estimation via Linear Regression." arxiv preprint:2012.01536

shapley-regression's People

Contributors

iancovert avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

shapley-regression's Issues

Error when using mseloss

I just transform True & False to 1&0 in census example. After training the model under lgb's rmse loss, I run the same code except that I replace the crossentropyloss with mseloss in the LossSHAP cooperative game.

The error message is as follows.

mse_error.png

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.