r – How to use SHAP on Elasticnet machine learning model?

I am running a machine learning analysis using elastic net (glmnet) in RStudio. I would like to use the shapr package to find the predictive proteins for my model. I trained my model with 5 repeats and 5 folds and then trained a final model based on that. Below is the code I used. The issue I am having is that shapr can’t be used on a custom model. I prefer Elastic Net to Xgboost, which is what I think it wants me to use.


#Calculate SHAP (Kernal) to determine which features matter for this model
#Use the Gaussian approach

explainer <- shapr(train_data, final_model)

target_variable <- as.numeric(target_variable)

p <- mean(target_variable)

explanation_gaussian <- explain(
  approach = "gaussian",
  explainer = explainer,
  prediction_zero = p

#Plot the resulting explanations for observations 1 and 6

plot(explanation_gaussian, plot_phi0 = FALSE, index_x_test = c(1, 6))
Error in get_model_specs(model) : 
  You passed a model to shapr which is not natively supported See ?shapr::shapr or the vignette
for more information on how to run shapr with custom models.

Source link

Leave a Reply

Your email address will not be published. Required fields are marked *