<title>reprex_reprex.R</title>
<script src="libs/header-attrs-2.10/header-attrs.js"></script>
<script src="libs/jquery-3.6.0/jquery-3.6.0.min.js"></script>
<script src="libs/anchor-sections-1.0.1/anchor-sections.js"></script>
<style type="text/css">
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
pre.sourceCode { margin: 0; }
print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
{ counter-reset: source-line 0; }
pre.numberSource code > span
{ position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
{ content: counter(source-line);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; display: inline-block;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
color: #aaaaaa;
}
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; }
div.sourceCode
{ }
screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #7d9029; } /* Attribute */
code span.bn { color: #40a070; } /* BaseN */
code span.bu { } /* BuiltIn */
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4070a0; } /* Char */
code span.cn { color: #880000; } /* Constant */
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
code span.dt { color: #902000; } /* DataType */
code span.dv { color: #40a070; } /* DecVal */
code span.er { color: #ff0000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #40a070; } /* Float */
code span.fu { color: #06287e; } /* Function */
code span.im { } /* Import */
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
code span.op { color: #666666; } /* Operator */
code span.ot { color: #007020; } /* Other */
code span.pp { color: #bc7a00; } /* Preprocessor */
code span.sc { color: #4070a0; } /* SpecialChar */
code span.ss { color: #bb6688; } /* SpecialString */
code span.st { color: #4070a0; } /* String */
code span.va { color: #19177c; } /* Variable */
code span.vs { color: #4070a0; } /* VerbatimString */
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
</style>
<div class="book-summary">
<nav role="navigation">
</nav>
</div>
<div class="book-body">
<div class="body-inner">
<div class="book-header" role="navigation">
<h1>
<i class="fa fa-circle-o-notch fa-spin"></i><a href="./">reprex_reprex.R</a>
</h1>
</div>
<div class="page-wrapper" tabindex="-1" role="main">
<div class="page-inner">
<section class="normal" id="section-">
## Registered S3 method overwritten by 'tune':
## method from
## required_pkgs.model_spec parsnip
## ── Attaching packages ────────────────────────────────────── tidymodels 0.1.3 ──
## ✓ broom 0.7.9 ✓ recipes 0.1.16
## ✓ dials 0.0.9 ✓ rsample 0.1.0
## ✓ dplyr 1.0.7 ✓ tibble 3.1.3
## ✓ ggplot2 3.3.5 ✓ tidyr 1.1.3
## ✓ infer 1.0.0 ✓ tune 0.1.6
## ✓ modeldata 0.1.1 ✓ workflows 0.2.3
## ✓ parsnip 0.1.7 ✓ workflowsets 0.1.0
## ✓ purrr 0.3.4 ✓ yardstick 0.0.8
## ── Conflicts ───────────────────────────────────────── tidymodels_conflicts() ──
## x purrr::discard() masks scales::discard()
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
## x recipes::step() masks stats::step()
## • Use tidymodels_prefer() to resolve common conflicts.
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ readr 2.0.1 ✓ forcats 0.5.1
## ✓ stringr 1.4.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x readr::col_factor() masks scales::col_factor()
## x purrr::discard() masks scales::discard()
## x dplyr::filter() masks stats::filter()
## x stringr::fixed() masks recipes::fixed()
## x dplyr::lag() masks stats::lag()
## x readr::spec() masks yardstick::spec()
library(palmerpenguins)
set.seed(99)
penguins_wo_missing_numeric <- penguins %>%
filter(across(where(is.numeric), ~!is.na(.x)))
penguin_split <- initial_split(penguins_wo_missing_numeric, prop = 0.8)
penguin_folds <- vfold_cv(training(penguin_split), v = 5)
usemodels::use_glmnet(
species ~ .,
data = training(penguin_split),
verbose = FALSE,
tune = TRUE,
colors = TRUE
)
## glmnet_recipe <-
## recipe(formula = species ~ ., data = training(penguin_split)) %>%
## step_novel(all_nominal(), -all_outcomes()) %>%
## step_dummy(all_nominal(), -all_outcomes()) %>%
## step_zv(all_predictors()) %>%
## step_normalize(all_predictors(), -all_nominal())
##
## glmnet_spec <-
## multinom_reg(penalty = tune(), mixture = tune()) %>%
## set_mode("classification") %>%
## set_engine("glmnet")
##
## glmnet_workflow <-
## workflow() %>%
## add_recipe(glmnet_recipe) %>%
## add_model(glmnet_spec)
##
## glmnet_grid <- tidyr::crossing(penalty = 10^seq(-6, -1, length.out = 20), mixture = c(0.05,
## 0.2, 0.4, 0.6, 0.8, 1))
##
## glmnet_tune <-
## tune_grid(glmnet_workflow, resamples = stop("add your rsample object"), grid = glmnet_grid)
glmnet_recipe <-
recipe(formula = species ~ ., data = training(penguin_split)) %>%
step_novel(all_nominal(), -all_outcomes()) %>%
step_dummy(all_nominal(), -all_outcomes()) %>%
step_zv(all_predictors()) %>%
step_normalize(all_predictors(), -all_nominal())
glmnet_spec <-
multinom_reg(penalty = tune(), mixture = tune()) %>%
set_mode("classification") %>%
set_engine("glmnet")
glmnet_workflow <-
workflow() %>%
add_recipe(glmnet_recipe) %>%
add_model(glmnet_spec)
glmnet_grid <- tidyr::crossing(
penalty = 10^seq(-6, -1, length.out = 3),
mixture = c(0.05, 0.6)
)
tune_grid(glmnet_workflow, resamples = penguin_folds, grid = glmnet_grid)
## ! Fold1: preprocessor 1/1: There are new levels in a factor: NA
## x Fold1: preprocessor 1/1, model 1/2: Error in lognet(xd, is.sparse, ix, jx, y, w...
## x Fold1: preprocessor 1/1, model 2/2: Error in lognet(xd, is.sparse, ix, jx, y, w...
## ! Fold2: preprocessor 1/1: There are new levels in a factor: NA
## x Fold2: preprocessor 1/1, model 1/2: Error in lognet(xd, is.sparse, ix, jx, y, w...
## x Fold2: preprocessor 1/1, model 2/2: Error in lognet(xd, is.sparse, ix, jx, y, w...
## ! Fold3: preprocessor 1/1: There are new levels in a factor: NA
## x Fold3: preprocessor 1/1, model 1/2: Error in lognet(xd, is.sparse, ix, jx, y, w...
## x Fold3: preprocessor 1/1, model 2/2: Error in lognet(xd, is.sparse, ix, jx, y, w...
## ! Fold4: preprocessor 1/1: There are new levels in a factor: NA
## x Fold4: preprocessor 1/1, model 1/2: Error in lognet(xd, is.sparse, ix, jx, y, w...
## x Fold4: preprocessor 1/1, model 2/2: Error in lognet(xd, is.sparse, ix, jx, y, w...
## ! Fold5: preprocessor 1/1: There are new levels in a factor: NA
## x Fold5: preprocessor 1/1, model 1/2: Error in lognet(xd, is.sparse, ix, jx, y, w...
## x Fold5: preprocessor 1/1, model 2/2: Error in lognet(xd, is.sparse, ix, jx, y, w...
## Warning: All models failed. See the `.notes` column.
## Warning: This tuning result has notes. Example notes on model fitting include:
## preprocessor 1/1, model 1/2: Error in lognet(xd, is.sparse, ix, jx, y, weights, offset, alpha, nobs, : NA/NaN/Inf in foreign function call (arg 5)
## preprocessor 1/1, model 2/2: Error in lognet(xd, is.sparse, ix, jx, y, weights, offset, alpha, nobs, : NA/NaN/Inf in foreign function call (arg 5)
## preprocessor 1/1, model 1/2: Error in lognet(xd, is.sparse, ix, jx, y, weights, offset, alpha, nobs, : NA/NaN/Inf in foreign function call (arg 5)
## # Tuning results
## # 5-fold cross-validation
## # A tibble: 5 × 4
## splits id .metrics .notes
## <list> <chr> <list> <list>
## 1 <split [218/55]> Fold1 <NULL> <tibble [3 × 1]>
## 2 <split [218/55]> Fold2 <NULL> <tibble [3 × 1]>
## 3 <split [218/55]> Fold3 <NULL> <tibble [3 × 1]>
## 4 <split [219/54]> Fold4 <NULL> <tibble [3 × 1]>
## 5 <split [219/54]> Fold5 <NULL> <tibble [3 × 1]>
# with step_unknown
glmnet_recipe <-
recipe(formula = species ~ ., data = training(penguin_split)) %>%
step_unknown(all_nominal(), -all_outcomes()) %>%
step_novel(all_nominal(), -all_outcomes()) %>%
step_dummy(all_nominal(), -all_outcomes()) %>%
step_zv(all_predictors()) %>%
step_normalize(all_predictors(), -all_nominal())
glmnet_workflow <-
glmnet_workflow %>%
update_recipe(glmnet_recipe)
tune_grid(glmnet_workflow, resamples = penguin_folds, grid = glmnet_grid)
## # Tuning results
## # 5-fold cross-validation
## # A tibble: 5 × 4
## splits id .metrics .notes
## <list> <chr> <list> <list>
## 1 <split [218/55]> Fold1 <tibble [12 × 6]> <tibble [0 × 1]>
## 2 <split [218/55]> Fold2 <tibble [12 × 6]> <tibble [0 × 1]>
## 3 <split [218/55]> Fold3 <tibble [12 × 6]> <tibble [0 × 1]>
## 4 <split [219/54]> Fold4 <tibble [12 × 6]> <tibble [0 × 1]>
## 5 <split [219/54]> Fold5 <tibble [12 × 6]> <tibble [0 × 1]>
</div>
</div>
</div>
</div>
<script src="libs/gitbook-2.6.7/js/app.min.js"></script>
<script src="libs/gitbook-2.6.7/js/lunr.js"></script>
<script src="libs/gitbook-2.6.7/js/clipboard.min.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-search.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-sharing.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-fontsettings.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-bookdown.js"></script>
<script src="libs/gitbook-2.6.7/js/jquery.highlight.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-clipboard.js"></script>
<script>
gitbook.require(["gitbook"], function(gitbook) {
gitbook.start({
"sharing": {
"github": true,
"facebook": false,
"twitter": false,
"linkedin": false,
"weibo": false,
"instapaper": false,
"vk": false,
"whatsapp": false,
"all": ["facebook", "twitter", "linkedin", "weibo", "instapaper"]
},
"fontsettings": {
"theme": "white",
"family": "sans",
"size": 2
},
"edit": {
"link": "https://github.com/r4ds/bookclub-tmwr/edit/main/%s",
"text": "Edit"
},
"history": {
"link": null,
"text": null
},
"view": {
"link": null,
"text": null
},
"download": null,
"search": false,
"toc": {
"collapse": "section"
}
});
});
</script>