diff --git a/docker-resources/plumber.R b/docker-resources/plumber.R index 0d26cbd..8df070f 100644 --- a/docker-resources/plumber.R +++ b/docker-resources/plumber.R @@ -123,17 +123,10 @@ function( # run the predictions # TODO Why does this seem to claim we're running in train / validate mode? - maybe_o2_delete <- function (obj) { - if (is.h2o(obj)) h2o.rm(obj) - } - - results_adults_h2o <- results_adults <- h2o.predict(ml_model_adult, h2o_predict_frame_adults) - on.exit(maybe_o2_delete(results_adults_h2o)) - results_minors_h2o <- results_minors <- h2o.predict(ml_model_minor, h2o_predict_frame_minors) - on.exit(maybe_o2_delete(results_adults_h2o)) - - results_adults <- as.data.frame(results_adults) - results_minors <- as.data.frame(results_minors) + results_adults <- h2o.predict(ml_model_adult, h2o_predict_frame_adults) + on.exit(h2o.rm(results_adults)) + results_minors <- h2o.predict(ml_model_minor, h2o_predict_frame_minors) + on.exit(h2o.rm(results_minors)) # for the case where we need this, it should be safe to assume # that the start week has the correct values @@ -142,6 +135,7 @@ function( # enrich the table of predictors with the results prediction_results_adults <- predictors %>% filter(Age >= 18) %>% + bind_cols(as.data.frame(results_adults)) %>% left_join(results_adults, by = join_by(person_id, encounter_id, location_id)) %>% # reduce data frame and rename the result select(person_id, encounter_id, location_id, rtc_date, predicted_prob_disengage = Disengaged) %>% @@ -159,6 +153,7 @@ function( prediction_results_minors <- predictors %>% filter(Age < 18) %>% + bind_cols(as.data.frame(results_minors)) %>% left_join(results_minors, by = join_by(person_id, encounter_id, location_id)) %>% # reduce data frame and rename the result select(person_id, encounter_id, location_id, rtc_date, predicted_prob_disengage = Disengaged) %>%