-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated for workshop at RStudio::conf 2020; added readme
- Loading branch information
Showing
378 changed files
with
77,691 additions
and
109,494 deletions.
There are no files selected for viewing
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
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) |
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
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") | ||
|
||
|
Oops, something went wrong.