Skip to content

Analytical computation of rolling and expanding Shapley values for time-series data.

Notifications You must be signed in to change notification settings

jasonjfoster/rollshap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rollshap

Overview

rollshap is a package that provides analytical computation of rolling and expanding Shapley values for time-series data.

Installation

Install the development version from GitHub:

# install.packages("devtools")
devtools::install_github("jasonjfoster/rollshap") # roll (>= 1.1.7)

Usage

Load the package and supply a dataset:

library(rollshap)

n <- 15
m <- 3
x <- matrix(rnorm(n * m), nrow = n, ncol = m)
y <- rnorm(n)
weights <- 0.9 ^ (n:1)

Then, to compute rolling and expanding Shapley values, use the roll_shap function:

# rolling Shapley values with complete windows
roll_shap(x, y, width = 5)

# rolling Shapley values with partial windows
roll_shap(x, y, width = 5, min_obs = 1)

# expanding Shapley values with partial windows
roll_shap(x, y, width = n, min_obs = 1)

# expanding Shapley values with partial windows and weights
roll_shap(x, y, width = n, min_obs = 1, weights = weights)

Note that handling of missing values is supported as well (see the min_obs, complete_obs, and na_restore arguments).

About

Analytical computation of rolling and expanding Shapley values for time-series data.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published