Skip to content

Commit 45c7d0b

Browse files
committed
documentation overhaul (#6)
describe more thoroughly what the _res_ objects are and the data they're predicting on.
1 parent 7cebbd2 commit 45c7d0b

11 files changed

+362
-57
lines changed

R/predict.R

+9-4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#'
1818
#' @examples
1919
#' \donttest{
20+
#' data(penguins_test)
21+
#'
2022
#' # build and fit a regression model stack
2123
#' reg_st <-
2224
#' stacks() %>%
@@ -25,8 +27,11 @@
2527
#' stack_blend() %>%
2628
#' stack_fit()
2729
#'
28-
#' # predict on the penguins data
29-
#' predict(reg_st, penguins)
30+
#' # predict on the penguins testing data
31+
#' predict(reg_st, penguins_test)
32+
#'
33+
#' # include the predictions from the members
34+
#' predict(reg_st, penguins_test, members = TRUE)
3035
#'
3136
#' # build and fit a classification model stack
3237
#' class_st <-
@@ -38,8 +43,8 @@
3843
#'
3944
#' # predict species, first as a class, then as
4045
#' # class probabilities
41-
#' predict(class_st, penguins)
42-
#' predict(class_st, penguins, type = "prob")
46+
#' predict(class_st, penguins_test)
47+
#' predict(class_st, penguins_test, type = "prob")
4348
#' }
4449
#'
4550
#' @importFrom stats predict

R/stack_add.R

+22-6
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,35 @@
2020
#' @template note_example_data
2121
#'
2222
#' @examples
23-
#'
24-
#' # initialize a stack and add some candidate members
25-
#' st <-
23+
#' \donttest{
24+
#' # put together a data stack using
25+
#' # tuning results for regression models
26+
#' reg_st <-
2627
#' stacks() %>%
2728
#' stack_add(reg_res_lr) %>%
2829
#' stack_add(reg_res_svm) %>%
2930
#' stack_add(reg_res_sp)
3031
#'
31-
#' # do the same with classification models
32-
#' st2 <-
32+
#' # do the same with multinomial classification models
33+
#' class_st <-
3334
#' stacks() %>%
3435
#' stack_add(class_res_nn) %>%
35-
#' stack_add(class_res_rf)
36+
#' stack_add(class_res_rf)
37+
#'
38+
#' # ...or binomial classification models
39+
#' log_st <-
40+
#' stacks() %>%
41+
#' stack_add(log_res_nn) %>%
42+
#' stack_add(log_res_rf)
43+
#'
44+
#' # use custom names for each model:
45+
#' log_st2 <-
46+
#' stacks() %>%
47+
#' stack_add(log_res_nn, name = "neural_network") %>%
48+
#' stack_add(log_res_rf, name = "random_forest")
49+
#' }
50+
#'
51+
#' @family core verbs
3652
#' @export
3753
stack_add <- function(data_stack, candidates,
3854
name = deparse(substitute(candidates)), ...) {

R/stack_blend.R

+18-3
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,32 @@
1616
#' @examples
1717
#' \donttest{
1818
#' # put together a data stack
19-
#' st <-
19+
#' reg_st <-
2020
#' stacks() %>%
2121
#' stack_add(reg_res_lr) %>%
2222
#' stack_add(reg_res_svm) %>%
2323
#' stack_add(reg_res_sp)
24-
#'
24+
#'
2525
#' # evaluate the data stack
26-
#' st %>%
26+
#' reg_st %>%
27+
#' stack_blend()
28+
#'
29+
#' # do the same with multinomial classification models
30+
#' class_st <-
31+
#' stacks() %>%
32+
#' stack_add(class_res_nn) %>%
33+
#' stack_add(class_res_rf) %>%
34+
#' stack_blend()
35+
#'
36+
#' # ...or binomial classification models
37+
#' log_st <-
38+
#' stacks() %>%
39+
#' stack_add(log_res_nn) %>%
40+
#' stack_add(log_res_rf) %>%
2741
#' stack_blend()
2842
#' }
2943
#'
44+
#' @family core verbs
3045
#' @export
3146
stack_blend <- function(data_stack, ...) {
3247
preds_formula <-

R/stack_fit.R

+19-2
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,35 @@
2323
#' @examples
2424
#' \donttest{
2525
#' # put together a data stack
26-
#' st <-
26+
#' reg_st <-
2727
#' stacks() %>%
2828
#' stack_add(reg_res_lr) %>%
2929
#' stack_add(reg_res_svm) %>%
3030
#' stack_add(reg_res_sp)
3131
#'
3232
#' # evaluate the data stack and fit the member models
33-
#' st %>%
33+
#' reg_st %>%
34+
#' stack_blend() %>%
35+
#' stack_fit()
36+
#'
37+
#' # do the same with multinomial classification models
38+
#' class_st <-
39+
#' stacks() %>%
40+
#' stack_add(class_res_nn) %>%
41+
#' stack_add(class_res_rf) %>%
42+
#' stack_blend() %>%
43+
#' stack_fit()
44+
#'
45+
#' # ...or binomial classification models
46+
#' log_st <-
47+
#' stacks() %>%
48+
#' stack_add(log_res_nn) %>%
49+
#' stack_add(log_res_rf) %>%
3450
#' stack_blend() %>%
3551
#' stack_fit()
3652
#' }
3753
#'
54+
#' @family core verbs
3855
#' @export
3956
stack_fit <- function(model_stack, data = NULL, ...) {
4057

R/stacks.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#'
1414
#' @return A `data_stack` object.
1515
#'
16-
#' @seealso [stack_add()]
16+
#' @family core verbs
1717
#'
1818
#' @export
1919
stacks <- function(...) {

man-roxygen/note_example_data.R

+38-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,40 @@
11
#' @section Example Data:
22
#'
3-
#' See \code{?example_data} to learn more about the \code{lin_reg_res},
4-
#' \code{reg_res_svm}, and \code{reg_res_sp} objects used in the examples below.
5-
#' Long story short, they're resample objects outputted from
6-
#' [tune::fit_resamples()] or [tune::tune_grid()] fitting \code{body_mass_g}
7-
#' with all other variables in [palmerpenguins::penguins] as predictors!
3+
#' These examples make use of data and resampling objects exported with the
4+
#' package. All of them are derived from test cases making use of the
5+
#' `penguins` dataset from Allison Horst's `palmerpenguins` package.
6+
#'
7+
#' The `penguins_train` and `penguins_test` objects are subsets of the
8+
#' penguins data for using in training and testing, respectively.
9+
#'
10+
#' Objects containing the substring `_res_` are `tune_results` objects
11+
#' for model specifications. The `reg` prefix indicates that the model
12+
#' definition is for use in regression, `class` indicates multinomial
13+
#' classification, and `log` (as in logistic) indicates binomial classification.
14+
#' The suffix indicates the model definition type. All of these `tune_results`
15+
#' objects are fitted on a 5-fold cross validation of the `penguins_train` data.
16+
#'
17+
#' For the regression setting, these `tune_results` objects reflect
18+
#' models specified to fit `body_mass_g` using all of the other variables
19+
#' as predictors. These objects include:
20+
#'
21+
#' * `reg_res_lr`: Fitted resamples for a linear regression model
22+
#' * `reg_res_sp`: Tuning results for a splines model
23+
#' * `reg_res_svm`: Tuning results for a support vector machine model
24+
#'
25+
#' In the multinomial classification setting, the relevant objects reflect
26+
#' models specified to fit `island` using all of the other variables as
27+
#' predictors. These objects include:
28+
#'
29+
#' * `class_res_nn`: Fitted resamples for a neural network model
30+
#' * `class_res_rf`: Tuning results for a random forest model
31+
#'
32+
#' In the binomial classification setting, the relevant objects reflect models
33+
#' specified to fit `sex` using all of the other variables as predictors.
34+
#' These objects include:
35+
#'
36+
#' * `log_res_nn`: Fitted resamples for a neural network model
37+
#' * `log_res_rf`: Tuning results for a random forest model
38+
#'
39+
#' See \code{?example_data} to learn more about these objects, as well as browse
40+
#' the source code that generated them.

man/predict.model_stack.Rd

+50-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/stack_add.Rd

+69-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)