Skip to content

Commit 7126b1d

Browse files
committed
update chunk headers to quarto style
1 parent b1c80f5 commit 7126b1d

File tree

2 files changed

+40
-19
lines changed

2 files changed

+40
-19
lines changed

README.Rmd

+4-2
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,15 @@ The name reflects the idea that tuning predictive models can be like turning a s
3737

3838
You can install the released version of dials from [CRAN](https://CRAN.R-project.org) with:
3939

40-
```{r, eval=FALSE}
40+
```{r}
41+
#| eval: false
4142
install.packages("dials")
4243
```
4344

4445
You can install the development version from Github with:
4546

46-
```{r, eval=FALSE}
47+
```{r}
48+
#| eval: false
4749
# install.packages("pak")
4850
pak::pak("tidymodels/dials")
4951
```

vignettes/dials.Rmd

+36-17
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ output:
88
toc: yes
99
---
1010

11-
```{r setup, include = FALSE}
11+
```{r}
12+
#| label: setup
13+
#| include: false
1214
knitr::opts_chunk$set(
1315
message = FALSE,
1416
digits = 3,
@@ -45,14 +47,16 @@ Otherwise, the information contained in parameter objects are different for diff
4547

4648
An example of a numeric tuning parameter is the cost-complexity parameter of CART trees, otherwise known as $C_p$. A parameter object for $C_p$ can be created in `dials` using:
4749

48-
```{r cp}
50+
```{r}
51+
#| label: cp
4952
library(dials)
5053
cost_complexity()
5154
```
5255

5356
Note that this parameter is handled in log units and the default range of values is between `10^-10` and `0.1`. The range of possible values can be returned and changed based on some utility functions. We'll use the pipe operator here:
5457

55-
```{r cp-range}
58+
```{r}
59+
#| label: cp-range
5660
library(dplyr)
5761
cost_complexity() %>% range_get()
5862
cost_complexity() %>% range_set(c(-5, 1))
@@ -64,7 +68,8 @@ cost_complexity(range = c(-5, 1))
6468

6569
Values for this parameter can be obtained in a few different ways. To get a sequence of values that span the range:
6670

67-
```{r cp-seq}
71+
```{r}
72+
#| label: cp-seq
6873
# Natural units:
6974
cost_complexity() %>% value_seq(n = 4)
7075
@@ -74,14 +79,17 @@ cost_complexity() %>% value_seq(n = 4, original = FALSE)
7479

7580
Random values can be sampled too. A random uniform distribution is used (between the range values). Since this parameter has a transformation associated with it, the values are simulated in the transformed scale and then returned in the natural units (although the `original` argument can be used here):
7681

77-
```{r cp-sim}
82+
```{r}
83+
#| label: cp-sim
7884
set.seed(5473)
7985
cost_complexity() %>% value_sample(n = 4)
8086
```
8187

8288
For CART trees, there is a discrete set of values that exist for a given data set. It may be a good idea to assign these possible values to the object. We can get them by fitting an initial `rpart` model and then adding the values to the object. For `mtcars`, there are only three values:
8389

84-
```{r rpart, error=TRUE}
90+
```{r}
91+
#| label: rpart
92+
#| error: true
8593
library(rpart)
8694
cart_mod <- rpart(mpg ~ ., data = mtcars, control = rpart.control(cp = 0.000001))
8795
cart_mod$cptable
@@ -96,14 +104,16 @@ mtcars_cp <- cost_complexity() %>% value_set(cp_vals)
96104

97105
The error occurs because the values are not in the transformed scale:
98106

99-
```{r rpart-cp}
107+
```{r}
108+
#| label: rpart-cp
100109
mtcars_cp <- cost_complexity() %>% value_set(log10(cp_vals))
101110
mtcars_cp
102111
```
103112

104113
Now, if a sequence or random sample is requested, it uses the set values:
105114

106-
```{r rpart-cp-vals}
115+
```{r}
116+
#| label: rpart-cp-vals
107117
mtcars_cp %>% value_seq(2)
108118
# Sampling specific values is done with replacement
109119
mtcars_cp %>%
@@ -113,7 +123,8 @@ mtcars_cp %>%
113123

114124
Any transformations from the `scales` package can be used with the numeric parameters, or a custom transformation generated with `scales::trans_new()`.
115125

116-
```{r custom-transform}
126+
```{r}
127+
#| label: custom-transform
117128
trans_raise <- scales::trans_new(
118129
"raise",
119130
transform = function(x) 2^x ,
@@ -126,7 +137,8 @@ custom_cost
126137
Note that if a transformation is used, the `range` argument specifies the parameter range _on the transformed scale_.
127138
For this version of `cost()`, parameter values are sampled between 1 and 10 and then transformed back to the original scale by the inverse `-log2()`. So on the original scale, the sampled values are between `-log2(10)` and `-log2(1)`.
128139

129-
```{r custom-cost}
140+
```{r}
141+
#| label: custom-cost
130142
-log2(c(10, 1))
131143
value_sample(custom_cost, 100) %>% range()
132144
```
@@ -136,13 +148,15 @@ value_sample(custom_cost, 100) %>% range()
136148

137149
In the discrete case there is no notion of a range. The parameter objects are defined by their discrete values. For example, consider a parameter for the types of kernel functions that is used with distance functions:
138150

139-
```{r wts}
151+
```{r}
152+
#| label: wts
140153
weight_func()
141154
```
142155

143156
The helper functions are analogues to the quantitative parameters:
144157

145-
```{r wts-ex}
158+
```{r}
159+
#| label: wts-ex
146160
# redefine values
147161
weight_func() %>% value_set(c("rectangular", "triangular"))
148162
weight_func() %>% value_sample(3)
@@ -159,7 +173,8 @@ The package contains two constructors that can be used to create new quantitativ
159173

160174
There are some cases where the range of parameter values are data dependent. For example, the upper bound on the number of neighbors cannot be known if the number of data points in the training set is not known. For that reason, some parameters have an _unknown_ placeholder:
161175

162-
```{r unk}
176+
```{r}
177+
#| label: unk
163178
mtry()
164179
sample_size()
165180
num_terms()
@@ -169,15 +184,17 @@ num_comp()
169184

170185
These values must be initialized prior to generating parameter values. The `finalize()` methods can be used to help remove the unknowns:
171186

172-
```{r finalize-mtry}
187+
```{r}
188+
#| label: finalize-mtry
173189
finalize(mtry(), x = mtcars[, -1])
174190
```
175191

176192
## Parameter Sets
177193

178194
These are collection of parameters used in a model, recipe, or other object. They can also be created manually and can have alternate identification fields:
179195

180-
```{r p-set}
196+
```{r}
197+
#| label: p-set
181198
glmnet_set <- parameters(list(lambda = penalty(), alpha = mixture()))
182199
glmnet_set
183200
@@ -193,7 +210,8 @@ Sets or combinations of parameters can be created for use in grid search. `grid_
193210

194211
For example, for a glmnet model, a regular grid might be:
195212

196-
```{r glm-reg}
213+
```{r}
214+
#| label: glm-reg
197215
grid_regular(
198216
mixture(),
199217
penalty(),
@@ -203,7 +221,8 @@ grid_regular(
203221

204222
and, similarly, a random grid is created using
205223

206-
```{r glm-rnd}
224+
```{r}
225+
#| label: glm-rnd
207226
set.seed(1041)
208227
grid_random(
209228
mixture(),

0 commit comments

Comments
 (0)