ModelOriented / treeshap

Compute SHAP values for your tree-based models using the TreeSHAP algorithm
https://modeloriented.github.io/treeshap/
GNU General Public License v3.0
78 stars 22 forks source link

Feature request: consolidated unify function #18

Closed nspyrison closed 9 months ago

nspyrison commented 2 years ago

Not sure if there are other modeling functions to look out for, but maybe something like:

unify <- function(model, x){
  .cl <- class(model)
  if("randomForest" %in% .cl){
    ret <- randomForest.unify(model, x)
  }else if("ranger" %in% .cl){
    ret <- ranger.unify(model, x)
  }else if("gbm" %in% .cl){
    ret <- gbm.unify(model, x)
  }else if("xgb.Booster" %in% .cl){
    ret <- xgboost.unify(model, x)
  }else if("lgb.Booster" %in% .cl){
    ret <- lightgbm.unify(model, x)
  }else if("catboost.Model" %in% .cl){
    ret <- catboost.unify(model, x)
  }else
    stop("Model is not a treeshap supported model.")
  ret
}
krzyzinskim commented 9 months ago

Great idea, I've implemented it in #30