Skip to content

Commit

Permalink
Updated for workshop at RStudio::conf 2020; added readme
Browse files Browse the repository at this point in the history
  • Loading branch information
topepo committed Jan 29, 2020
1 parent 5b95cdc commit 50f8213
Show file tree
Hide file tree
Showing 378 changed files with 77,691 additions and 109,494 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
\# RStudio Training Materials for tidymodels

These directories contain training materials that we've presented for the `tidymodels` packages. We keep this repo up-to-date with the most recent content.

They are organized by the length of training. The current set of materials:

* `two day`: from RStudio::conf 2020

* `one day`: 2019 Symposium on Data Science and Statistics (these are fairly out-of-date and don't include newer packages)

* `half day`: 2019 R/Pharma conference (these are fairly out-of-date and don't include newer packages)
68 changes: 68 additions & 0 deletions two day/Chicago_grid.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
library(tidymodels)
library(tune)

library(doMC)
registerDoMC(cores = 8)

# ------------------------------------------------------------------------------

set.seed(7898)
data_folds <- rolling_origin(Chicago, initial = 364 * 15, assess = 7 * 4, skip = 7 * 4, cumulative = FALSE)

# ------------------------------------------------------------------------------

library(stringr)
us_hol <-
timeDate::listHolidays() %>%
str_subset("(^US)|(Easter)")

chi_rec <-
recipe(ridership ~ ., data = Chicago) %>%
step_holiday(date, holidays = us_hol) %>%
step_date(date) %>%
step_rm(date) %>%
step_dummy(all_nominal()) %>%
step_zv(all_predictors())

mars_rec <-
chi_rec %>%
step_normalize(one_of(!!stations)) %>%
step_pca(one_of(!!stations), num_comp = tune("pca comps"))

mars_mod <-
mars(num_terms = tune("mars terms"), prod_degree = tune(), prune_method = "none") %>%
set_engine("earth") %>%
set_mode("regression")

chi_wflow <-
workflow() %>%
add_recipe(mars_rec) %>%
add_model(mars_mod)

chi_grid <-
expand.grid(
`pca comps` = 0:20,
prod_degree = 1:2,
`mars terms` = 2:100
)

all_res <-
tune_grid(
chi_wflow,
resamples = data_folds,
grid = chi_grid,
control = control_grid(verbose = TRUE)
)

print(all_res$.notes[[1]])

complete_mars_grid <-
all_res %>%
collect_metrics() %>%
dplyr::filter(.metric == "rmse")

save(complete_mars_grid, file = "complete_mars_grid.RData")

q("no")


Loading

0 comments on commit 50f8213

Please sign in to comment.