Update for modelr API changes

This commit is contained in:
hadley 2016-06-15 08:27:35 -05:00
parent d3b75fb19b
commit 0e2ccfeba3
1 changed files with 6 additions and 17 deletions

View File

@ -34,6 +34,7 @@ library(ggplot2)
# Tools for working with models # Tools for working with models
library(broom) library(broom)
library(modelr) library(modelr)
library(splines)
# Tools for working with lots of models # Tools for working with lots of models
library(purrr) library(purrr)
@ -105,8 +106,8 @@ preds %>%
``` ```
```{r} ```{r}
boots <- rerun(100, bootstrap(df)) boot <- bootstrap(df, 100)
mods <- boots %>% map(safely(my_model)) %>% transpose() mods <- boot$strap %>% map(safely(my_model)) %>% transpose()
ok <- mods$error %>% map_lgl(is.null) ok <- mods$error %>% map_lgl(is.null)
``` ```
@ -124,22 +125,10 @@ preds %>%
We could instead use cross-validation to focus on a summary of model quality. It basically works like this: We could instead use cross-validation to focus on a summary of model quality. It basically works like this:
```{r} ```{r}
part <- partition(df, c(train = 0.9, test = 0.1)) cv <- crossv_mcmc(df, 100, test = 0.3)
part
mod <- my_model(part$train) mods <- map(cv$train, my_model)
rmse(mod, part$test) rmses <- map2_dbl(mods, cv$test, rmse)
```
And re-can repeat that many times:
```{r}
parts <- 100 %>%
rerun(partition(df, c(train = 0.7, test = 0.3))) %>%
transpose()
mods <- map(parts$train, my_model)
rmses <- map2_dbl(mods, parts$test, rmse)
data_frame(x = rmses) %>% data_frame(x = rmses) %>%
ggplot(aes(x)) + ggplot(aes(x)) +