Skip to content

Commit 8931c44

Browse files
committed
scoring ignores empty forecasts
1 parent 158063c commit 8931c44

File tree

1 file changed

+34
-23
lines changed

1 file changed

+34
-23
lines changed

R/targets/score_targets.R

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -64,29 +64,40 @@ score_forecasts <- function(latest_data, forecasts, target) {
6464
if (target == "wk inc covid prop ed visits") {
6565
forecasts_formatted %<>% mutate(value = value * 100)
6666
}
67-
scores <-
68-
forecasts_formatted %>%
69-
filter(output_type == "quantile") %>%
70-
filter(location %nin% c("US", "60", "66", "78")) %>%
71-
hubEvals::score_model_out(
72-
truth_data,
73-
metrics = c("wis", "ae_median", "interval_coverage_50", "interval_coverage_90"),
74-
summarize = TRUE,
75-
by = c("model_id", "target", "reference_date", "location", "horizon")
76-
)
77-
scores %>%
78-
left_join(
79-
get_population_data() %>%
80-
select(state_id, state_code),
81-
by = c("location" = "state_code")
82-
) %>%
83-
rename(
84-
forecaster = model_id,
85-
forecast_date = reference_date,
86-
ahead = horizon,
87-
geo_value = state_id
88-
) %>%
89-
select(-location)
67+
tryCatch(
68+
{
69+
scores <-
70+
forecasts_formatted %>%
71+
filter(output_type == "quantile") %>%
72+
filter(location %nin% c("US", "60", "66", "78")) %>%
73+
hubEvals::score_model_out(
74+
truth_data,
75+
metrics = c("wis", "ae_median", "interval_coverage_50", "interval_coverage_90"),
76+
summarize = TRUE,
77+
by = c("model_id", "target", "reference_date", "location", "horizon")
78+
)
79+
scores %>%
80+
left_join(
81+
get_population_data() %>%
82+
select(state_id, state_code),
83+
by = c("location" = "state_code")
84+
) %>%
85+
rename(
86+
forecaster = model_id,
87+
forecast_date = reference_date,
88+
ahead = horizon,
89+
geo_value = state_id
90+
) %>%
91+
select(-location)
92+
},
93+
error = function(e) {
94+
if (rlang::cnd_message(e) == "\033[1m\033[22m\033[33m!\033[39m After removing rows with NA values in the data, no forecasts are left.") {
95+
return(tibble())
96+
} else {
97+
rlang::abort(e)
98+
}
99+
}
100+
)
90101
}
91102

92103
render_score_plot <- function(score_report_rmd, scores, forecast_dates, disease, target) {

0 commit comments

Comments
 (0)