You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: vignettes/articles/Scratch.Rmd
+28-20Lines changed: 28 additions & 20 deletions
Original file line number
Diff line number
Diff line change
@@ -64,14 +64,14 @@ A row for "unknown" modes is not needed in this object.
64
64
65
65
Now, we enumerate the _main arguments_ for each engine. `parsnip` standardizes the names of arguments across different models and engines. For example, random forest and boosting use multiple trees to create the ensemble. Instead of using different argument names, `parsnip` standardizes on `trees` and the underlying code translates to the actual arguments used by the different functions.
66
66
67
-
In our case, the MDA argument name will be "subclasses".
67
+
In our case, the MDA argument name will be "sub_classes".
68
68
69
69
Here, the object name will have the suffix `_arg_key` and will have columns for the engines and rows for the arguments. The entries for the data frame are the actual arguments for each engine (and is `NA` when an engine doesn't have that argument). Ours:
70
70
71
71
```{r arg-key}
72
72
mixture_da_arg_key <- data.frame(
73
-
mda = "subclasses",
74
-
row.names = "subclasses",
73
+
mda = "sub_classes",
74
+
row.names = "sub_classes",
75
75
stringsAsFactors = FALSE
76
76
)
77
77
```
@@ -89,27 +89,25 @@ The internals of `parsnip` will use these objects during the creation of the mod
89
89
This is a fairly simple function that can follow a basic template. The main arguments to our function will be:
90
90
91
91
* The mode. If the model can do more than one mode, you might default this to "unknown". In our case, since it is only a classification model, it makes sense to default it to that mode.
92
-
* The argument names (`subclasses` here). These should be defaulted to `NULL`.
93
-
* An argument, `others`, that can be used to pass in other arguments to the underlying model fit functions.
94
-
*`...`, although they are not currently used. We encourage developers to move the `...` after mode so that users are encouraged to use named arguments to the model specification.
92
+
* The argument names (`sub_classes` here). These should be defaulted to `NULL`.
93
+
*`...` is used to pass in other arguments to the underlying model fit functions.
Copy file name to clipboardExpand all lines: vignettes/parsnip_Intro.Rmd
+42-35Lines changed: 42 additions & 35 deletions
Original file line number
Diff line number
Diff line change
@@ -77,24 +77,23 @@ The arguments to the default function are:
77
77
args(rand_forest)
78
78
```
79
79
80
-
However, there might be other arguments that you would like to change or allow to vary. These are accessible using the `others` option. This is a named list of arguments in the form of the underlying function being called. For example, `ranger` has an option to set the internal random number seed. To set this to a specific value:
80
+
However, there might be other arguments that you would like to change or allow to vary. These are accessible using the `...` slot. This is a named list of arguments in the form of the underlying function being called. For example, `ranger` has an option to set the internal random number seed. To set this to a specific value:
81
81
82
82
```{r rf-seed}
83
83
rf_with_seed <- rand_forest(
84
-
trees = 2000, mtry = varying(),
85
-
others = list(seed = 63233),
84
+
trees = 2000,
85
+
mtry = varying(),
86
+
seed = 63233,
86
87
mode = "regression"
87
88
)
88
89
rf_with_seed
89
90
```
90
91
91
-
If the model function contains the ellipses (`...`), these additional arguments can be passed along using `others`.
fit(rf_mod, mpg ~ ., data = mtcars, engine = "randomForest")
153
152
```
154
153
155
154
```
156
-
## parsnip model object
157
-
##
158
-
## Call:
159
-
## randomForest(x = as.data.frame(x), y = y, ntree = 2000)
160
-
## Type of random forest: regression
161
-
## Number of trees: 2000
162
-
## No. of variables tried at each split: 3
163
-
##
164
-
## Mean of squared residuals: 5.6
165
-
## % Var explained: 84.1
155
+
#> parsnip model object
156
+
#>
157
+
#>
158
+
#> Call:
159
+
#> randomForest(x = as.data.frame(x), y = y, ntree = ~2000)
160
+
#> Type of random forest: regression
161
+
#> Number of trees: 2000
162
+
#> No. of variables tried at each split: 3
163
+
#>
164
+
#> Mean of squared residuals: 5.6
165
+
#> % Var explained: 84.1
166
166
```
167
+
168
+
Note that, in the case of the `ranger` fit, the call object shows `num.trees = ~2000`. The tilde is the consequence of `parsnip` using quosures to process the model specification's arguments.
169
+
170
+
Normally, when a function is executed, the function's arguments are immediately evaluated. In the case of `parsnip`, the model specification's arguments are _not_; the expression is captured along with the environment where it should be evaluated. That is what a quosure does.
171
+
172
+
`parsnip` uses these expressions to make a model fit call that is evaluated. The tilde in the call above reflects that the argument was captured using a quosure.
0 commit comments