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 23 forks source link

treeshap.model_unified fails with data.table input #36

Open Balaika opened 7 months ago

Balaika commented 7 months ago

In treeshap.model_unified function, this line does not behave as expected if x is a data.table :

x <- x[,colnames(x) %in% unified_model$feature_names]

x=data.table(a=1:3,b=2:4)
x[,colnames(x)%in%colnames(x)]
[1] TRUE TRUE
x%>%as.data.frame%>%.[,colnames(x)%in%colnames(x)]
  a b
1 1 2
2 2 3
3 3 4

I suggest to convert x to a data.frame when x is a data.table