diff --git a/articles/basic_use.html b/articles/basic_use.html index 5b50d50..c3c7d4c 100644 --- a/articles/basic_use.html +++ b/articles/basic_use.html @@ -133,7 +133,7 @@

Overview
  1. Models that know how to calculate SHAP values: XGBoost, LightGBM, -h2o (boosted trees).
  2. +and h2o.
  3. SHAP crunchers like {fastshap}, {kernelshap}, {treeshap}, {fastr}, and {DALEX}.
  4. SHAP matrix and corresponding feature values.
  5. @@ -297,7 +297,9 @@

    shapr

    H2O

    -

    If you work with a boosted trees H2O model:

    +

    H2O supports TreeSHAP for boosted trees and random forests. For other +models, model agnostic method based on marginal expectations are used, +requiring a background dataset.

     library(shapviz)
     library(h2o)
    @@ -305,10 +307,18 @@ 

    H2O h2o.init() iris2 <- as.h2o(iris) -fit <- h2o.gbm(colnames(iris[-1]), "Sepal.Length", training_frame = iris2) -shp <- shapviz(fit, X_pred = iris) -sv_force(shp, row_id = 1) -sv_dependence(shp, "Species")

    + +# Random forest +fit_rf <- h2o.randomForest(colnames(iris[-1]), "Sepal.Length", training_frame = iris2) +shp_rf <- shapviz(fit_rf, X_pred = iris) +sv_force(shp_rf, row_id = 1) +sv_dependence(shp_rf, "Species") + +# Linear model +fit_lm <- h2o.glm(colnames(iris[-1]), "Sepal.Length", training_frame = iris2) +shp_lm <- shapviz(fit_lm, X_pred = iris, background_frame = iris2) +sv_force(shp_lm, row_id = 1) +sv_dependence(shp_lm, "Species")

    treeshap diff --git a/articles/geographic_files/figure-html/unnamed-chunk-3-1.png b/articles/geographic_files/figure-html/unnamed-chunk-3-1.png index 2b1d245..aa924e7 100644 Binary files a/articles/geographic_files/figure-html/unnamed-chunk-3-1.png and b/articles/geographic_files/figure-html/unnamed-chunk-3-1.png differ diff --git a/articles/multiple_output_files/figure-html/unnamed-chunk-2-1.png b/articles/multiple_output_files/figure-html/unnamed-chunk-2-1.png index 522dcff..3a105c4 100644 Binary files a/articles/multiple_output_files/figure-html/unnamed-chunk-2-1.png and b/articles/multiple_output_files/figure-html/unnamed-chunk-2-1.png differ diff --git a/articles/multiple_output_files/figure-html/unnamed-chunk-2-2.png b/articles/multiple_output_files/figure-html/unnamed-chunk-2-2.png index d2e4ab7..dc891df 100644 Binary files a/articles/multiple_output_files/figure-html/unnamed-chunk-2-2.png and b/articles/multiple_output_files/figure-html/unnamed-chunk-2-2.png differ diff --git a/articles/multiple_output_files/figure-html/unnamed-chunk-2-3.png b/articles/multiple_output_files/figure-html/unnamed-chunk-2-3.png index e5fa726..adf8edf 100644 Binary files a/articles/multiple_output_files/figure-html/unnamed-chunk-2-3.png and b/articles/multiple_output_files/figure-html/unnamed-chunk-2-3.png differ diff --git a/articles/multiple_output_files/figure-html/unnamed-chunk-3-1.png b/articles/multiple_output_files/figure-html/unnamed-chunk-3-1.png index abd0ee5..4d54a2e 100644 Binary files a/articles/multiple_output_files/figure-html/unnamed-chunk-3-1.png and b/articles/multiple_output_files/figure-html/unnamed-chunk-3-1.png differ diff --git a/articles/multiple_output_files/figure-html/unnamed-chunk-3-2.png b/articles/multiple_output_files/figure-html/unnamed-chunk-3-2.png index 72b99db..e87225a 100644 Binary files a/articles/multiple_output_files/figure-html/unnamed-chunk-3-2.png and b/articles/multiple_output_files/figure-html/unnamed-chunk-3-2.png differ diff --git a/authors.html b/authors.html index 2575496..30d6cc0 100644 --- a/authors.html +++ b/authors.html @@ -92,14 +92,14 @@

    Citation

    -

    Mayer M (2024). +

    Mayer M (2025). shapviz: SHAP Visualizations. R package version 0.9.7, https://modeloriented.github.io/shapviz/, https://github.com/ModelOriented/shapviz.

    @Manual{,
       title = {shapviz: SHAP Visualizations},
       author = {Michael Mayer},
    -  year = {2024},
    +  year = {2025},
       note = {R package version 0.9.7, https://modeloriented.github.io/shapviz/},
       url = {https://github.com/ModelOriented/shapviz},
     }
    diff --git a/index.html b/index.html index 457b1c6..a8aa197 100644 --- a/index.html +++ b/index.html @@ -122,7 +122,7 @@

    Overview

    SHAP and feature values are stored in a “shapviz” object that is built from:

      -
    1. Models that know how to calculate SHAP values: XGBoost, LightGBM, H2O (tree-based models).
    2. +
    3. Models that know how to calculate SHAP values: XGBoost, LightGBM, and H2O.
    4. SHAP crunchers like {fastshap}, {kernelshap}, {treeshap}, {fastr}, and {DALEX}.
    5. SHAP matrix and corresponding feature values.
    diff --git a/news/index.html b/news/index.html index 7a92898..a7e9665 100644 --- a/news/index.html +++ b/news/index.html @@ -78,7 +78,8 @@

    Changelog

    Documentation

    -
    • H2O random forests (regression and binary classification) are now supported as well (fast TreeSHAP) #163.
    • +
      • H2O now supports passing background data for model agnostic SHAP. This is now easier visible in {shapviz}, see https://github.com/h2oai/h2o-3/issues/16463.
      • +
      • H2O random forests (regression and binary classification) now support TreeSHAP as well #163.

    Compatibility

    diff --git a/pkgdown.yml b/pkgdown.yml index 4771f48..d16562f 100644 --- a/pkgdown.yml +++ b/pkgdown.yml @@ -6,4 +6,4 @@ articles: geographic: geographic.html multiple_output: multiple_output.html tidymodels: tidymodels.html -last_built: 2024-11-30T14:23Z +last_built: 2025-01-10T12:09Z diff --git a/reference/shapviz.html b/reference/shapviz.html index 4e64e4b..8daea1e 100644 --- a/reference/shapviz.html +++ b/reference/shapviz.html @@ -3,7 +3,7 @@ from a fitted model of type XGBoost, LightGBM, or -H2O (tree-based models). +H2O. Furthermore, shapviz() can digest the results of @@ -96,7 +96,7 @@

    Initialize "shapviz" Object

    This function creates an object of class "shapviz" from a matrix of SHAP values, or from a fitted model of type

    • XGBoost,

    • LightGBM, or

    • -
    • H2O (tree-based models).

    • +
    • H2O.

    Furthermore, shapviz() can digest the results of

    • fastshap::explain(),

    • shapr::explain(),

    • treeshap::treeshap(),

    • @@ -156,14 +156,17 @@

      Initialize "shapviz" Object

      # S3 method for class 'kernelshap' shapviz(object, X = object[["X"]], which_class = NULL, collapse = NULL, ...) -# S3 method for class 'H2ORegressionModel' -shapviz(object, X_pred, X = as.data.frame(X_pred), collapse = NULL, ...) - -# S3 method for class 'H2OBinomialModel' -shapviz(object, X_pred, X = as.data.frame(X_pred), collapse = NULL, ...) - # S3 method for class 'H2OModel' -shapviz(object, X_pred, X = as.data.frame(X_pred), collapse = NULL, ...)
    +shapviz( + object, + X_pred, + X = as.data.frame(X_pred), + collapse = NULL, + background_frame = NULL, + output_space = FALSE, + output_per_reference = FALSE, + ... +)
    @@ -224,6 +227,24 @@

    Arguments

    Should SHAP interactions be calculated (default is FALSE)? Only available for XGBoost.

    + +
    background_frame
    +

    Background dataset for baseline SHAP or marginal SHAP. +Only for H2O models.

    + + +
    output_space
    +

    If model has link function, this argument controls whether the +SHAP values should be linearly (= approximately) transformed to the original scale +(if TRUE). The default is to return the values on link scale. +Only for H2O models.

    + + +
    output_per_reference
    +

    Switches between different algorithms, see +?h2o::h2o.predict_contributions for details. +Only for H2O models.

    +

    Value

    @@ -259,9 +280,7 @@

    Methods (by class)

  6. shapviz(shapr): Creates a "shapviz" object from shapr::explain().

  7. shapviz(kernelshap): Creates a "shapviz" object from an object of class 'kernelshap'. This includes results of kernelshap(), permshap(), and additive_shap().

  8. -
  9. shapviz(H2ORegressionModel): Creates a "shapviz" object from a (tree-based) H2O regression model.

  10. -
  11. shapviz(H2OBinomialModel): Creates a "shapviz" object from a (tree-based) H2O binary classification model.

  12. -
  13. shapviz(H2OModel): Creates a "shapviz" object from a (tree-based) H2O model (base class).

  14. +
  15. shapviz(H2OModel): Creates a "shapviz" object from an H2O model.

  16. See also

    @@ -382,7 +401,7 @@

    Examples

    mx all.equal(mx[[3]], x) } -#> [LightGBM] [Info] Auto-choosing col-wise multi-threading, the overhead of testing was 0.000018 seconds. +#> [LightGBM] [Info] Auto-choosing col-wise multi-threading, the overhead of testing was 0.000021 seconds. #> You can set `force_col_wise=true` to remove the overhead. #> [LightGBM] [Info] Total Bins 98 #> [LightGBM] [Info] Number of data points in the train set: 150, number of used features: 4 diff --git a/reference/sv_dependence-4.png b/reference/sv_dependence-4.png index 1cc4f4b..bba53a6 100644 Binary files a/reference/sv_dependence-4.png and b/reference/sv_dependence-4.png differ diff --git a/reference/sv_dependence-7.png b/reference/sv_dependence-7.png index 01aa13a..49d20d7 100644 Binary files a/reference/sv_dependence-7.png and b/reference/sv_dependence-7.png differ diff --git a/reference/sv_dependence2D-2.png b/reference/sv_dependence2D-2.png index 5b9efdf..e82c844 100644 Binary files a/reference/sv_dependence2D-2.png and b/reference/sv_dependence2D-2.png differ diff --git a/reference/sv_force-1.png b/reference/sv_force-1.png index a80952c..c832b9b 100644 Binary files a/reference/sv_force-1.png and b/reference/sv_force-1.png differ diff --git a/reference/sv_force-2.png b/reference/sv_force-2.png index 4ad0529..08e2c14 100644 Binary files a/reference/sv_force-2.png and b/reference/sv_force-2.png differ diff --git a/reference/sv_force-3.png b/reference/sv_force-3.png index fbd3305..b047bd8 100644 Binary files a/reference/sv_force-3.png and b/reference/sv_force-3.png differ diff --git a/reference/sv_importance-1.png b/reference/sv_importance-1.png index 5c792a4..ec6438d 100644 Binary files a/reference/sv_importance-1.png and b/reference/sv_importance-1.png differ diff --git a/reference/sv_importance-2.png b/reference/sv_importance-2.png index 1595150..d6240de 100644 Binary files a/reference/sv_importance-2.png and b/reference/sv_importance-2.png differ