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.
library(glmnet)
library(pROC)
library(shapr)
library(caret)
#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(
test_data,
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.