library(palmerpenguins)
library(tidyverse)
penguins <- palmerpenguins::penguins %>%
na.omit()
mod <- lm(body_mass_g ~ bill_length_mm + bill_depth_mm + sex, data = penguins)
bind_cols(
tibble(.pred = predict(mod, penguins)),
relocate(penguins, body_mass_g)
) %>%
group_by(species) %>%
yardstick::mape(body_mass_g, .pred)
#> # A tibble: 3 x 4
#> species .metric .estimator .estimate
#> <fct> <chr> <chr> <dbl>
#> 1 Adelie mape standard 9.66
#> 2 Chinstrap mape standard 12.1
#> 3 Gentoo mape standard 6.42Created on 2021-03-17 by the reprex package (v0.3.0)