Created
May 5, 2019 18:08
-
-
Save schnee/22ba28327d361e9dfe1ca73bb85c398c to your computer and use it in GitHub Desktop.
What considerations are important in choosing between the two styles below? Interpretability, maintainability, speed, other?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(purrr) | |
y_test <- sample(0:9, 2000, replace = TRUE) | |
pred1 <- sample(0:9, 2000, replace= TRUE) | |
pred2 <- sample(0:9, 2000, replace= TRUE) | |
preds <- list(pred1, pred2) | |
# want to apply the following to preds | |
# sum(diag(table(y_test, pred)))/length(y_test) | |
# | |
# this | |
# | |
preds %>% | |
map(table, y_test) %>% | |
map(diag) %>% | |
map(sum) %>% | |
map_dbl(.f = function(x){x/length(y_test)}) | |
# | |
# or this | |
# | |
preds %>% | |
map_dbl(~{sum(diag(table(y_test, .x)))/length(y_test)}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment