Giter Club home page Giter Club logo

vip's Introduction

vip: Variable Importance Plots

CRAN_Status_Badge R-CMD-check Coverage Status Downloads The R Journal

Overview

vip is an R package for constructing variable importance plots (VIPs). VIPs are part of a larger framework referred to as interpretable machine learning (IML), which includes (but not limited to): partial dependence plots (PDPs) and individual conditional expectation (ICE) curves. While PDPs and ICE curves (available in the R package pdp) help visualize feature effects, VIPs help visualize feature impact (either locally or globally). An in-progress, but comprehensive, overview of IML can be found here: https://github.com/christophM/interpretable-ml-book.

Many supervised learning algorithms can naturally emit some measure of importance for the features used in the model, and these approaches are embedded in many different packages. The downside, however, is that each package uses a different function and interface and it can be challenging (and distracting) to have to remember each one (e.g., remembering to use xgb.importance() for xgboost models and gbm.summary() for gbm models). With vip you get one consistent interface to computing variable importance for many types of supervised learning models across a number of packages. Additionally, vip offers a number of model-agnostic procedures for computing feature importance (see the next section) as well an experimental function for quantifying the strength of potential interaction effects. For details and example usage, visit the vip package website.

Features

  • Model-based variable importance - Compute variable importance specific to a particular model (like a random forest, gradient boosted decision trees, or multivariate adaptive regression splines) from a wide range of R packages (e.g., randomForest, ranger, xgboost, and many more). Also supports the caret and parsnip (starting with version 0.0.4) packages.

  • Permutation-based variable importance - An efficient implementation of the permutation feature importance algorithm discussed in this chapter from Christoph Molnar’s Interpretable Machine Learning book.

  • Shapley-based variable importance - An efficient implementation of feature importance based on the popular Shapley values via the fastshap package.

  • Variance-based variable importance - Compute variable importance using a simple feature importance ranking measure (FIRM) approach. For details, see see Greenwell et al. (2018) and Scholbeck et al. (2019).

Installation

# The easiest way to get vip is to install it from CRAN:
install.packages("vip")

# Alternatively, you can install the development version from GitHub:
if (!requireNamespace("remotes")) {
  install.packages("remotes")
}
remotes::install_github("koalaverse/vip")

vip's People

Contributors

atusy avatar bfgray3 avatar bgreenwell avatar bradleyboehmke avatar brandongreenwell-8451 avatar topepo 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  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  avatar  avatar  avatar  avatar

vip's Issues

TensorFlow example

Fitting the same model here, we can construct PDPs, ICE curves, and VIPs with minimal code using the pred.fun argument to pdp::partial():

# Centered ICE curves
library(pdp)
pfun <- function(object, newdata) {
  predict_proba(object, x = as.matrix(newdata)) %>%
    as.vector()  # %>% mean()  # uncomment for PDP instead of ICE curves
}
pd <- partial(model_keras, pred.var = "TotalCharges", progress = "text",
              pred.fun = pfun, train = as.data.frame(x_train_tbl))
autoplot(pd, alpha = 0.01, center = TRUE)

# Variable importance plot (VIP)
library(vip)
vip(model_keras, method = "ice", feature_names = names(x_train_tbl), 
    pred.fun = pfun, train = as.data.frame(x_train_tbl), num_features = 35)

ice-tensorflow
vip-tensoflow

Add support for h2o package

Some support for regression models is there, but it needs to be tested! Also, h2o.varimp() output is model specific!

Error: Permutation-based variable importance scores not yet implemented.

Hi. I am using vip to measure variable importance scores from my super learner model.
And I get the following error message:

install.packages("vip")
library(vip)
set.seed(150) # for reproducibility
sl <- SuperLearner(Y = label, X = train,
SL.library=c("SL.randomForest", "SL.glmnet", "SL.svm"),
method = "method.NNLS", verbose=TRUE)
words <- colnames(train)
p1 <- vi(sl, method = "perm", obs = label, feature_names = words)
Error: Permutation-based variable importance scores not yet implemented.

What does this error message mean?
Also, does vip support super learner models?
I would appreciate your help. Thanks!

Add nsim argument to vi_permute()

The nsim argument (which will default to 1) enables multiple replications of shuffling each feature to reduce Monte Carlo error and help stabilize results from run to run (and maybe even produce standard deviations?).

imp <- vi_permute(fit, nsim = 10, ...)

Permutation-based VI

Maybe something like...

vip(model, type = "permute", train = trn, metric = "rmse")

vint function is broken

  • Unnecessary check on feature_names argument;
  • Passes feature_names to pdp::partial() using the wrong argument name.

Best way to handle numeric and categorical features

Argument FUN could be a list which, for example, defaults to

FUN = list(
  "con" = stats::sd,  # continuous
  "cat" = function(x) diff(x) / 4  # categorical
)

However, the denominator in "cat" should depend on the number of categories, say K.

Add tests

Should not be hard to reach >90% test coverage.

Case-specific variable importance scores

Using method = "ice" it is possible to compute VI scores for each individual case. For example,

vi(fit, method = "ice", case = TRUE)

What's the best way to plot this?

New options

Add options to control bar width (when bar = TRUE) and orientation (e.g., horizontal = TRUE).

update dependencies?

What are your thoughts on using ggplot2 >= 3.0.0, moving dplyr >= 0.7.0 to Imports, and getting rid of plyr (no commits in over two years) and magrittr/tibble (dplyr exports the pipe and tibble()) from Imports? I could do a pull request if you're intersted.

Start thinking package restructure

Helper functions:

vi_model()  # a generic with various methods: vi_model.randomForest()
vi_partial()
vi_permute()
vi_shapely()  # <- this would def be nice!
...

which would then be called by vi() as in

vi(fit, type = "model", ...)

Note: will have to figure out how to deal with naming conflicts! For example, if fit is a "randomForest" object, then issues would arise with

vi(fit, type = "model", type = 2)

One work around is to prefix argument names with a . like in plyr:

vi(fit, .type = "model",  .feature_names = c("x1", "x2"), 
   # Arguments to be passed on through ...
    type = 2)

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.