comparison_metric <- function(df, metric = c("rmse")) {
stopifnot(inherits(df, "data.frame"))
stopifnot(all(c("actual", "expected", "weight") %in% colnames(df)))
metric <- match.arg(metric)
if(metric == "rmse") {
df %>%
dplyr::mutate(squared_residual = (actual - expected)^2) %>%
dplyr::summarize(rmse = sqrt(sum(squared_residual) / dplyr::n())) %>%
unlist(use.names = FALSE)
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.