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

Keras prediction issue #42

Closed
dax44 opened this issue May 30, 2022 · 2 comments
Closed

Keras prediction issue #42

dax44 opened this issue May 30, 2022 · 2 comments

Comments

@dax44
Copy link

dax44 commented May 30, 2022

I've learned Keras sequential model with the following code:

library(keras)
library(fastshap)

x_train <- iris |> 
  slice(1:100) |> 
  select(-Species) |> 
  as.matrix()
y_train <- iris |> 
  slice(1:100) |> 
  select(Species) |> 
  mutate(Species = as.numeric(Species)-1) |> 
  as.matrix()

mod <- keras_model_sequential()
mod |> 
  layer_dense(units = 16, input_shape = 4) |> 
  layer_activation(activation = "relu") |> 
  layer_dropout(rate = 0.3) |> 
  layer_dense(units = 1, activation = "sigmoid")
mod |> 
  compile(optimizer = "nadam",
          loss = loss_binary_crossentropy())

history <- fit(
  object = mod, 
  x = x_train, 
  y = y_train,
  batch_size = 10, 
  epochs = 30,
  validation_split = 0.1
)

Then I tried to build explainer with fastshap explainer

p_fun <- function(object, newdata) predict(object, x = newdata)
shp_exp <- fastshap::explain(mod, 
                             X = x_train, 
                             pred_wrapper = p_fun)
shp_exp

but my shp_exp has only one row... why?

@dax44
Copy link
Author

dax44 commented Jun 7, 2022

Is this project died?

@mayer79
Copy link
Contributor

mayer79 commented Feb 4, 2023

The predict function should return only one numeric value: #14

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants