Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot rename colnames/dimnames in post-processing #98

Closed
madprogramer opened this issue Jul 12, 2023 · 2 comments
Closed

Cannot rename colnames/dimnames in post-processing #98

madprogramer opened this issue Jul 12, 2023 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@madprogramer
Copy link

Consider a simple force plot generated from the diamonds dataset:

library(shapviz)
library(ggplot2)
library(xgboost)

set.seed(3653)

x <- c("carat", "cut", "color", "clarity")
dtrain <- xgb.DMatrix(data.matrix(diamonds[x]), label = diamonds$price)
fit <- xgb.train(params = list(learning_rate = 0.1), data = dtrain, nrounds = 65)

# Explanation data
dia_small <- diamonds[sample(nrow(diamonds), 2000), ]

shp <- shapviz(fit, X_pred = data.matrix(dia_small[x]), X = dia_small)

sv_force(shp, row_id = 1)

image

Because I currently live in Europe, I would like to change the color=F in this plot to colour=F as in UK ortography.

> colnames(shp)
[1] "carat"   "cut"     "color"   "clarity"
> colnames(shp) <- c("carat", "cut", "colour", "clarity")
Error in dimnames(x) <- dn : 'dimnames' applied to non-array

Although the shapviz class defines an S3 method for colnames, there is no way to alter the colnames/dimnames because the class does not have array-like inheritance for the underlying matrix. Passing dimnames for both axes of the dimensions will also fail:

> dimnames(shp)
[[1]]
NULL

[[2]]
[1] "carat"   "cut"     "color"   "clarity"

> dimnames(shp) <- list(NULL, c("carat", "cut", "colour", "clarity"))
Error in dimnames(shp) <- list(NULL, c("carat", "cut", "colour", "clarity")) : 
  'dimnames' applied to non-array

Essentially, I want to be able to post-process the shapviz object for human readibility. Another use-case could be when working with categorical variables and using collapse (#7 ) where renaming variables before the shapviz object is generated might not be feasible.

@mayer79
Copy link
Collaborator

mayer79 commented Jul 12, 2023

Good idea. We can add a dimnames.shapviz<- method, which would automatically give you also the possibility to use

colnames(shp) <- c("carat", "cut", "colour", "clarity")

Note to myself: don't forget SHAP interaction arrays.

@mayer79 mayer79 self-assigned this Jul 12, 2023
@mayer79 mayer79 added the enhancement New feature or request label Jul 12, 2023
@mayer79
Copy link
Collaborator

mayer79 commented Jul 12, 2023

Implemented in #99

@mayer79 mayer79 closed this as completed Jul 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants