bgreenwell / fastshap

Fast approximate Shapley values in R
https://bgreenwell.github.io/fastshap/
113 stars 18 forks source link

force_plot not working #23

Closed mikeguggis closed 2 years ago

mikeguggis commented 3 years ago

I can't get force_plot to work with the example code or the article (https://bgreenwell.github.io/fastshap/articles/forceplot.html) code.

Restarting R session...

> remove.packages("fastshap")
Removing package from ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library’
(as ‘lib’ is unspecified)
> 
> install.packages("fastshap")
trying URL 'https://cran.rstudio.com/bin/macosx/contrib/4.0/fastshap_0.0.5.tgz'
Content type 'application/x-gzip' length 561465 bytes (548 KB)
==================================================
downloaded 548 KB

The downloaded binary packages are in
    /var/folders/fs/n8fm688d7139p9zjkl1llsbdv6n1th/T//RtmpBRZmED/downloaded_packages
> 
> library(fastshap)
> 
> # Load the sample data; see ?datasets::mtcars for details
> data(mtcars)
> 
> # Fit a projection pursuit regression model
> mtcars.ppr <- ppr(mpg ~ ., data = mtcars, nterms = 1)
> 
> # Compute approximate Shapley values using 10 Monte Carlo simulations
> set.seed(101)  # for reproducibility
> shap <- explain(mtcars.ppr, X = subset(mtcars, select = -mpg), nsim = 10, 
+                 pred_wrapper = predict, adjust = TRUE)
Warning message:
The `x` argument of `as_tibble.matrix()` must have unique column names if `.name_repair` is omitted as of tibble 2.0.0.
Using compatibility `.name_repair`.
This warning is displayed once every 8 hours.
Call `lifecycle::last_warnings()` to see where this warning was generated. 
> 
> # Visualize first explanation
> preds <- predict(mtcars.ppr, newdata = mtcars)
> x <- subset(mtcars, select = -mpg)[1L, ]  # take first row of feature values
> force_plot(shap[1L, ], baseline = mean(preds), feature_values = x)
Error in py_call_impl(callable, dots$args, dots$keywords) : 
  TypeError: save_html() got an unexpected keyword argument 'plot_html'

And here is my session info

> sessionInfo()
R version 4.0.3 (2020-10-10)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.7

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] fastshap_0.0.5

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.6         pillar_1.6.1       compiler_4.0.3     plyr_1.8.6        
 [5] tools_4.0.3        jsonlite_1.7.2     lifecycle_1.0.0    tibble_3.1.2      
 [9] gtable_0.3.0       lattice_0.20-44    png_0.1-7          pkgconfig_2.0.3   
[13] rlang_0.4.11       Matrix_1.3-3       DBI_1.1.1          rstudioapi_0.13   
[17] gridExtra_2.3      dplyr_1.0.6        generics_0.1.0     vctrs_0.3.8       
[21] xgboost_1.4.1.1    grid_4.0.3         tidyselect_1.1.1   reticulate_1.20   
[25] glue_1.4.2         data.table_1.14.1  R6_2.5.0           fansi_0.5.0       
[29] ggplot2_3.3.4      purrr_0.3.4        magrittr_2.0.1     scales_1.1.1      
[33] ellipsis_0.3.2     matrixStats_0.59.0 assertthat_0.2.1   abind_1.4-5       
[37] colorspace_2.0-1   utf8_1.2.1         munsell_0.5.0      crayon_1.4.1      
IPython could not be loaded!
> 
bgreenwell commented 3 years ago

Hi @mikeguggis, your problem seems related to this issue.

bgreenwell commented 2 years ago

All plotting functions have been deprecated in favor of using shapviz.