Skip to content

Instantly share code, notes, and snippets.

@brshallo
Created March 17, 2021 16:10
Show Gist options
  • Select an option

  • Save brshallo/24394f9bd808a3a9c7331985ff6089a9 to your computer and use it in GitHub Desktop.

Select an option

Save brshallo/24394f9bd808a3a9c7331985ff6089a9 to your computer and use it in GitHub Desktop.
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.42

Created on 2021-03-17 by the reprex package (v0.3.0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment