When I run shapviz::shapviz
, I get the error:
Error in s[, nms, drop = FALSE] : incorrect number of dimensions
I believe I am using the correct predictors for the model, which are being “retained” for me by recipes::bake
.
I’m also removing NAs, just incase.
Any idea what is going on here?
syllable_mod <- bundle::unbundle(lyricassessr::syllable_classifier_bundle)
# The tidymodels prediction works:
preds <- predict(syllable_mod, new_data = audio_features, type = "prob") %>%
dplyr::rename_with(~stringr::str_remove_all(.x, ".pred_")) %>%
tidyr::pivot_longer(dplyr::everything(),
names_to = "Syllable", values_to = "Probability") %>%
dplyr::arrange(dplyr::desc(Probability))
xgb_model <- parsnip::extract_fit_engine(syllable_mod)
# Make sure there are no NAs, just incase (1 is a meaningless number for now..)
audio_features <- audio_features %>%
dplyr::mutate(across(everything(), ~ ifelse(is.na(.x), 1, .x)))
audio_features_prepped <- recipes::bake(
lyricassessr::prepped_recipe,
recipes::has_role("predictor"),
new_data = audio_features) %>%
dplyr::mutate(across(everything(), ~ ifelse(is.na(.x), 1, .x)))
# Make sure audio_features agree with the retained (prepped) features
audio_features <- audio_features %>%
dplyr::select(dplyr::all_of(names(audio_features_prepped)))
shap_values <- shapviz::shapviz(xgb_model, X_pred = as.matrix(audio_features_prepped), X = as.matrix(audio_features))