Closed
Description
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)
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.