You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Safely make predictions on fitted workflowinternal_make_wflw_predictions<-function(.model_tbl, .splits_obj){
# Tidyeval ----model_tbl<-.model_tblsplits_obj<-.splits_objcol_nms<- colnames(model_tbl)
# Checks ----if (!inherits(model_tbl, "tidyaml_mod_spec_tbl")){
rlang::abort(
message="'.model_tbl' must inherit a class of 'tidyaml_mod_spec_tbl",
use_cli_format=TRUE
)
}
if (!"fitted_wflw"%in%col_nms){
rlang::abort(
message="Missing the column 'wflw'",
use_cli_format=TRUE
)
}
if (!".model_id"%in%col_nms){
rlang::abort(
message="Missing the column '.model_id'",
use_cli_format=TRUE
)
}
# Manipulation# Make a group split object listmodel_factor_tbl<-model_tbl %>%
dplyr::mutate(.model_id=forcats::as_factor(.model_id))
models_list<-model_factor_tbl %>%
dplyr::group_split(.model_id)
# Make the predictions on the fitted workflow object using purrr imapwflw_preds_list<-models_list %>%
purrr::imap(
.f=function(obj, id){
# Pull the fitted workflow column and then pluck itfitted_wflw=obj %>% dplyr::pull(7) %>% pluck(1)
# Create a safe stats::predictsafe_stats_predict<-purrr::safely(
stats::predict,
otherwise="Error - Could not make predictions",
quiet=FALSE
)
# Return the predictionsret<- safe_stats_predict(
fitted_wflw,
new_data=rsample::training(splits_obj$splits)
)
res<-ret %>% purrr::pluck("result")
return(res)
}
)
return(wflw_preds_list)
}
Example:
> internal_make_wflw_predictions(mod_fitted_tbl, splits_obj)
Error:noapplicablemethodfor'predict'appliedtoanobjectofclass"character"
[[1]]
[[1]]$result# A tibble: 24 × 1.pred<dbl>123.2218.9315.4417.7515.6616.8715.5819.7911.71022.6# … with 14 more rows# ℹ Use `print(n = ...)` to see more rows
[[1]]$errorNULL
[[2]]
[[2]]$result
[1] "Error - Could not make predictions"
[[2]]$error<simpleErrorin UseMethod("predict"):noapplicablemethodfor'predict'appliedtoanobjectofclass"character">
[[3]]
[[3]]$result# A tibble: 24 × 1.pred<dbl>123.2218.9315.4417.7515.6616.8715.5819.7911.71022.6# … with 14 more rows# ℹ Use `print(n = ...)` to see more rows
[[3]]$errorNULL``
The text was updated successfully, but these errors were encountered:
Function:
Example:
The text was updated successfully, but these errors were encountered: