Skip to content

Commit f2df9f7

Browse files
simonpcouchhfrick
andauthored
clarify references to model specifications and fits (#1189)
--------- Co-authored-by: Hannah Frick <[email protected]>
1 parent b180de8 commit f2df9f7

33 files changed

+115
-49
lines changed

R/aaa_multi_predict.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#' Model predictions across many sub-models
44
#'
55
#' For some models, predictions can be made on sub-models in the model object.
6-
#' @param object A `model_fit` object.
6+
#' @param object A [model fit][model_fit].
77
#' @param new_data A rectangular data object, such as a data frame.
88
#' @param type A single character value or `NULL`. Possible values are
99
#' `"numeric"`, `"class"`, `"prob"`, `"conf_int"`, `"pred_int"`, `"quantile"`,
@@ -38,7 +38,7 @@ multi_predict.default <- function(object, ...) {
3838
#' @export
3939
predict.model_spec <- function(object, ...) {
4040
cli::cli_abort(
41-
"You must {.fun fit} your model specification
41+
"You must {.fun fit} your {.help [model specification](parsnip::model_spec)}
4242
before you can use {.fun predict}."
4343
)
4444
}

R/arguments.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ check_eng_args <- function(args, obj, core_args) {
3535
#' `set_args()` can be used to modify the arguments of a model specification while
3636
#' `set_mode()` is used to change the model's mode.
3737
#'
38-
#' @param object A model specification.
38+
#' @param object A [model specification][model_spec].
3939
#' @param ... One or more named model arguments.
4040
#' @param mode A character string for the model type (e.g. "classification" or
4141
#' "regression")
@@ -134,7 +134,7 @@ maybe_eval <- function(x) {
134134
#' Evaluate parsnip model arguments
135135
#' @export
136136
#' @keywords internal
137-
#' @param spec A model specification
137+
#' @param spec A [model specification][model_spec].
138138
#' @param ... Not used.
139139
eval_args <- function(spec, ...) {
140140
spec$args <- purrr::map(spec$args, maybe_eval)

R/augment.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#'
33
#' `augment()` will add column(s) for predictions to the given data.
44
#'
5-
#' @param x A `model_fit` object produced by [fit.model_spec()] or
5+
#' @param x A [model fit][model_fit] produced by [fit.model_spec()] or
66
#' [fit_xy.model_spec()].
77
#' @param eval_time For censored regression models, a vector of time points at
88
#' which the survival probability is estimated.

R/case_weights.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ patch_formula_environment_with_case_weights <- function(formula,
7272
#' Not all modeling engines can incorporate case weights into their
7373
#' calculations. This function can determine whether they can be used.
7474
#'
75-
#' @param spec A parsnip model specification.
75+
#' @param spec A parsnip [model specification][model_spec].
7676
#' @return A single logical.
7777
#' @examples
7878
#' case_weights_allowed(linear_reg())

R/convert_data.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@
160160
}
161161

162162

163-
#' @param object An object of class `model_fit`.
163+
#' @param object A [model fit][model_fit].
164164
#' @inheritParams predict.model_fit
165165
#' @rdname convert_helpers
166166
#' @keywords internal

R/discrim_flexible.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ discrim_flexible <-
5151
# ------------------------------------------------------------------------------
5252

5353
#' Update a model specification
54-
#' @param object A model specification.
54+
#' @param object A [model specification][model_spec].
5555
#' @param ... Not used for `update()`.
5656
#' @param fresh A logical for whether the arguments should be
5757
#' modified in-place of or replaced wholesale.
@@ -92,7 +92,7 @@ check_args.discrim_flexible <- function(object, call = rlang::caller_env()) {
9292
check_number_whole(args$prod_degree, min = 1, allow_null = TRUE, call = call, arg = "prod_degree")
9393
check_number_whole(args$num_terms, min = 1, allow_null = TRUE, call = call, arg = "num_terms")
9494
check_string(args$prune_method, allow_empty = FALSE, allow_null = TRUE, call = call, arg = "prune_method")
95-
95+
9696
invisible(object)
9797
}
9898

R/engines.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ load_libs <- function(x, quiet, attach = FALSE) {
8282
#' `set_engine("ranger", importance = "permutation")`.
8383
#'
8484
#'
85-
#' @param object A model specification.
85+
#' @param object A [model specification][model_spec].
8686
#' @param engine A character string for the software that should
8787
#' be used to fit the model. This is highly dependent on the type
8888
#' of model (e.g. linear regression, random forest, etc.).

R/extract.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#' These functions extract various elements from a parsnip object. If they do
55
#' not exist yet, an error is thrown.
66
#'
7-
#' - `extract_spec_parsnip()` returns the parsnip model specification.
7+
#' - `extract_spec_parsnip()` returns the parsnip [model specification][model_spec].
88
#'
99
#' - `extract_fit_engine()` returns the engine specific fit embedded within
1010
#' a parsnip model fit. For example, when using [parsnip::linear_reg()]

R/fit.R

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ fit.model_spec <-
116116
...
117117
) {
118118
if (object$mode == "unknown") {
119-
cli::cli_abort("Please set the mode in the model specification.")
119+
cli::cli_abort(
120+
"Please set the mode in the {.help [model specification](parsnip::model_spec)}."
121+
)
120122
}
121123
control <- condense_control(control, control_parsnip())
122124
check_case_weights(case_weights, object)
@@ -249,7 +251,10 @@ fit_xy.model_spec <-
249251
...
250252
) {
251253
if (object$mode == "unknown") {
252-
cli::cli_abort("Please set the mode in the model specification.")
254+
cli::cli_abort(
255+
"Please set the mode in the
256+
{.help [model specification](parsnip::model_spec)}."
257+
)
253258
}
254259

255260
if (inherits(object, "surv_reg")) {

R/model_object_docs.R

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,32 @@
1-
#' Model Specification Information
1+
#' Model Specifications
22
#'
3+
#' @description
34
#'
4-
#' An object with class "model_spec" is a container for
5+
#' The parsnip package splits the process of fitting models into two steps:
6+
#'
7+
#' 1) Specify how a model will be fit using a _model specification_
8+
#' 2) Fit a model using the model specification
9+
#'
10+
#' This is a different approach to many other model interfaces in R, like `lm()`,
11+
#' where both the specification of the model and the fitting happens in one
12+
#' function call. Splitting the process into two steps allows users to
13+
#' iteratively define model specifications throughout the model development
14+
#' process.
15+
#'
16+
#' This intermediate object that defines how the model will be fit is called
17+
#' a _model specification_ and has class `model_spec`. Model type functions,
18+
#' like [linear_reg()] or [boost_tree()], return `model_spec` objects.
19+
#'
20+
#' Fitted model objects, resulting from passing a `model_spec` to
21+
#' [fit()][fit.model_spec()] or [fit_xy][fit_xy.model_spec()], have
22+
#' class `model_fit`, and contain the original `model_spec` objects inside
23+
#' them. See [?model_fit][model_fit] for more on that object type, and
24+
#' [?extract_spec_parsnip][extract_spec_parsnip.model_fit] to
25+
#' extract `model_spec`s from `model_fit`s.
26+
#'
27+
#' @details
28+
#'
29+
#' An object with class `"model_spec"` is a container for
530
#' information about a model that will be fit.
631
#'
732
#' The main elements of the object are:
@@ -140,10 +165,18 @@
140165
#' @name model_spec
141166
NULL
142167

143-
#' Model Fit Object Information
168+
#' Model Fit Objects
169+
#'
170+
#' @description
171+
#'
172+
#' Model fits are trained [model specifications][model_spec] that are
173+
#' ready to [predict][predict.model_fit] on new data. Model fits have class
174+
#' `model_fit` and, usually, a subclass referring to the engine
175+
#' used to fit the model.
144176
#'
177+
#' @details
145178
#'
146-
#' An object with class "model_fit" is a container for
179+
#' An object with class `"model_fit"` is a container for
147180
#' information about a model that has been fit to the data.
148181
#'
149182
#' The main elements of the object are:

R/predict.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#' `predict()` can be used for all types of models and uses the
55
#' "type" argument for more specificity.
66
#'
7-
#' @param object An object of class `model_fit`.
7+
#' @param object A [model fit][model_fit].
88
#' @param new_data A rectangular data object, such as a data frame.
99
#' @param type A single character value or `NULL`. Possible values
1010
#' are `"numeric"`, `"class"`, `"prob"`, `"conf_int"`, `"pred_int"`,

R/req_pkgs.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#' @description
44
#' `r lifecycle::badge("deprecated")`
55
#'
6-
#' @param x A model specification or fit.
6+
#' @param x A [model specification][model_spec] or [fit][model_fit].
77
#' @param ... Not used.
88
#' @return A character string of package names (if any).
99
#' @details

R/required_pkgs.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#' Determine required packages for a model
22
#'
3-
#' @param x A model specification or fit.
3+
#' @param x A [model specification][model_spec] or [fit][model_fit].
44
#' @param infra Should parsnip itself be included in the result?
55
#' @param ... Not used.
66
#' @return A character vector

R/translate.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#' Resolve a Model Specification for a Computational Engine
22
#'
3-
#' `translate()` will translate a model specification into a code
3+
#' `translate()` will translate a [model specification][model_spec] into a code
44
#' object that is specific to a particular engine (e.g. R package).
55
#' It translates generic parameters to their counterparts.
66
#'
7-
#' @param x A model specification.
7+
#' @param x A [model specification][model_spec].
88
#' @param engine The computational engine for the model (see `?set_engine`).
99
#' @param ... Not currently used.
1010
#' @details

R/update.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#' @inheritParams svm_linear
1919
#' @inheritParams svm_poly
2020
#' @inheritParams svm_rbf
21-
#' @param object A model specification.
21+
#' @param object A [model specification][model_spec].
2222
#' @param parameters A 1-row tibble or named list with _main_
2323
#' parameters to update. Use **either** `parameters` **or** the main arguments
2424
#' directly when updating. If the main arguments are used,

man/augment.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/case_weights_allowed.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/convert_helpers.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/eval_args.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/extract-parsnip.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/model_fit.Rd

Lines changed: 8 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/model_spec.Rd

Lines changed: 26 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/multi_predict.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/other_predict.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/parsnip_update.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/predict.model_fit.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/req_pkgs.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/required_pkgs.model_spec.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/set_args.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)