dimanche 12 septembre 2021

FInding Shapely Value of features

Currently, I am working on a project to estimate the shapely value of features and therefore I have used the below code to randomly select few (2) columns at a time and finding the shapely value. However, the method gives me an error which is difficult to identify. Hope if anyone can help

data("Boston", package = "MASS")
dt<-cbind(Boston$lstat,Boston$rm,Boston$dis,Boston$indus)
Var1<-Boston[,sample(ncol(dt), size = 1), drop = FALSE]
Var2<-Boston[,sample(ncol(dt), size = 1), drop = FALSE]
Var3<-Boston$medv
modt<-cbind(Var1,Var2,Var3)
varmod<-lm(Var3~.,data=modt)

summary(varmod)


x_var<-c(colnames(modt[1]),colnames(modt[2]))
y_var<-"Var3"
x_train <- as.matrix(modt[-1:-6, x_var])
y_train <- as.matrix(modt[-1:-6, y_var])
x_test <- as.matrix(modt[1:6, x_var])
y_test <- as.matrix(modt[1:6, y_var])

explainer <- shapr(x_train,varmod )
p <- mean(y_train)
explan<-explain(
  x_test,
  explainer=explainer,
  approach="empirical",
  prediction_zero=p
)

Error: Error in UseMethod("explain") : no applicable method for 'explain' applied to an object of class "c('matrix', 'double', 'numeric')"




Aucun commentaire:

Enregistrer un commentaire