Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clarify references to model specifications and fits #1189

Merged
merged 8 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions R/aaa_multi_predict.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#' Model predictions across many sub-models
#'
#' For some models, predictions can be made on sub-models in the model object.
#' @param object A `model_fit` object.
#' @param object A [model fit][model_fit].
#' @param new_data A rectangular data object, such as a data frame.
#' @param type A single character value or `NULL`. Possible values are
#' `"numeric"`, `"class"`, `"prob"`, `"conf_int"`, `"pred_int"`, `"quantile"`,
Expand Down Expand Up @@ -38,7 +38,7 @@ multi_predict.default <- function(object, ...) {
#' @export
predict.model_spec <- function(object, ...) {
cli::cli_abort(
"You must {.fun fit} your model specification
"You must {.fun fit} your {.help [model specification](parsnip::model_spec)}
before you can use {.fun predict}."
)
}
Expand Down
4 changes: 2 additions & 2 deletions R/arguments.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ check_eng_args <- function(args, obj, core_args) {
#' `set_args()` can be used to modify the arguments of a model specification while
#' `set_mode()` is used to change the model's mode.
#'
#' @param object A model specification.
#' @param object A [model specification][model_spec].
#' @param ... One or more named model arguments.
#' @param mode A character string for the model type (e.g. "classification" or
#' "regression")
Expand Down Expand Up @@ -134,7 +134,7 @@ maybe_eval <- function(x) {
#' Evaluate parsnip model arguments
#' @export
#' @keywords internal
#' @param spec A model specification
#' @param spec A [model specification][model_spec].
#' @param ... Not used.
eval_args <- function(spec, ...) {
spec$args <- purrr::map(spec$args, maybe_eval)
Expand Down
2 changes: 1 addition & 1 deletion R/augment.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#'
#' `augment()` will add column(s) for predictions to the given data.
#'
#' @param x A `model_fit` object produced by [fit.model_spec()] or
#' @param x A [model fit][model_fit] produced by [fit.model_spec()] or
#' [fit_xy.model_spec()].
#' @param eval_time For censored regression models, a vector of time points at
#' which the survival probability is estimated.
Expand Down
2 changes: 1 addition & 1 deletion R/case_weights.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ patch_formula_environment_with_case_weights <- function(formula,
#' Not all modeling engines can incorporate case weights into their
#' calculations. This function can determine whether they can be used.
#'
#' @param spec A parsnip model specification.
#' @param spec A parsnip [model specification][model_spec].
#' @return A single logical.
#' @examples
#' case_weights_allowed(linear_reg())
Expand Down
2 changes: 1 addition & 1 deletion R/convert_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
}


#' @param object An object of class `model_fit`.
#' @param object A [model fit][model_fit].
#' @inheritParams predict.model_fit
#' @rdname convert_helpers
#' @keywords internal
Expand Down
4 changes: 2 additions & 2 deletions R/discrim_flexible.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ discrim_flexible <-
# ------------------------------------------------------------------------------

#' Update a model specification
#' @param object A model specification.
#' @param object A [model specification][model_spec].
#' @param ... Not used for `update()`.
#' @param fresh A logical for whether the arguments should be
#' modified in-place of or replaced wholesale.
Expand Down Expand Up @@ -92,7 +92,7 @@ check_args.discrim_flexible <- function(object, call = rlang::caller_env()) {
check_number_whole(args$prod_degree, min = 1, allow_null = TRUE, call = call, arg = "prod_degree")
check_number_whole(args$num_terms, min = 1, allow_null = TRUE, call = call, arg = "num_terms")
check_string(args$prune_method, allow_empty = FALSE, allow_null = TRUE, call = call, arg = "prune_method")

invisible(object)
}

Expand Down
2 changes: 1 addition & 1 deletion R/engines.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ load_libs <- function(x, quiet, attach = FALSE) {
#' `set_engine("ranger", importance = "permutation")`.
#'
#'
#' @param object A model specification.
#' @param object A [model specification][model_spec].
#' @param engine A character string for the software that should
#' be used to fit the model. This is highly dependent on the type
#' of model (e.g. linear regression, random forest, etc.).
Expand Down
2 changes: 1 addition & 1 deletion R/extract.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#' These functions extract various elements from a parsnip object. If they do
#' not exist yet, an error is thrown.
#'
#' - `extract_spec_parsnip()` returns the parsnip model specification.
#' - `extract_spec_parsnip()` returns the parsnip [model specification][model_spec].
#'
#' - `extract_fit_engine()` returns the engine specific fit embedded within
#' a parsnip model fit. For example, when using [parsnip::linear_reg()]
Expand Down
9 changes: 7 additions & 2 deletions R/fit.R
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ fit.model_spec <-
...
) {
if (object$mode == "unknown") {
cli::cli_abort("Please set the mode in the model specification.")
cli::cli_abort(
"Please set the mode in the {.help [model specification](parsnip::model_spec)}."
)
}
control <- condense_control(control, control_parsnip())
check_case_weights(case_weights, object)
Expand Down Expand Up @@ -249,7 +251,10 @@ fit_xy.model_spec <-
...
) {
if (object$mode == "unknown") {
cli::cli_abort("Please set the mode in the model specification.")
cli::cli_abort(
"Please set the mode in the
{.help [model specification](parsnip::model_spec)}."
)
}

if (inherits(object, "surv_reg")) {
Expand Down
41 changes: 37 additions & 4 deletions R/model_object_docs.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,32 @@
#' Model Specification Information
#' Model Specifications
#'
#' @description
#'
#' An object with class "model_spec" is a container for
#' The parsnip package splits the process of fitting models into two steps:
#'
#' 1) Specify how a model will be fit using a _model specification_
#' 2) Fit a model using the model specification
#'
#' This is a different approach to many other model interfaces in R, like `lm()`,
#' where both the specification of the model and the fitting happens in one
#' function call. Splitting the process into two steps allows users to
#' iteratively define model specifications throughout the model development
#' process.
#'
#' This intermediate object that defines how the model will be fit is called
#' a _model specification_ and has class `model_spec`. Model type functions,
#' like [linear_reg()] or [boost_tree()], return `model_spec` objects.
#'
#' Fitted model objects, resulting from passing a `model_spec` to
#' [fit()][fit.model_spec()] or [fit_xy][fit_xy.model_spec()], have
#' class `model_fit`, and contain the original `model_spec` objects inside
#' them. See [?model_fit][model_fit] for more on that object type, and
#' [?extract_spec_parsnip][extract_spec_parsnip.model_fit] to
#' extract `model_spec`s from `model_fit`s.
#'
#' @details
#'
#' An object with class `"model_spec"` is a container for
#' information about a model that will be fit.
#'
#' The main elements of the object are:
Expand Down Expand Up @@ -140,10 +165,18 @@
#' @name model_spec
NULL

#' Model Fit Object Information
#' Model Fit Objects
#'
#' @description
#'
#' Model fits are trained [model specifications][model_spec] that are
#' ready to [predict][predict.model_fit] on new data. Model fits have class
#' `model_fit` and, usually, a subclass referring to the engine
#' used to fit the model.
#'
#' @details
#'
#' An object with class "model_fit" is a container for
#' An object with class `"model_fit"` is a container for
#' information about a model that has been fit to the data.
#'
#' The main elements of the object are:
Expand Down
2 changes: 1 addition & 1 deletion R/predict.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#' `predict()` can be used for all types of models and uses the
#' "type" argument for more specificity.
#'
#' @param object An object of class `model_fit`.
#' @param object A [model fit][model_fit].
#' @param new_data A rectangular data object, such as a data frame.
#' @param type A single character value or `NULL`. Possible values
#' are `"numeric"`, `"class"`, `"prob"`, `"conf_int"`, `"pred_int"`,
Expand Down
2 changes: 1 addition & 1 deletion R/req_pkgs.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#' @description
#' `r lifecycle::badge("deprecated")`
#'
#' @param x A model specification or fit.
#' @param x A [model specification][model_spec] or [fit][model_fit].
#' @param ... Not used.
#' @return A character string of package names (if any).
#' @details
Expand Down
2 changes: 1 addition & 1 deletion R/required_pkgs.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' Determine required packages for a model
#'
#' @param x A model specification or fit.
#' @param x A [model specification][model_spec] or [fit][model_fit].
#' @param infra Should parsnip itself be included in the result?
#' @param ... Not used.
#' @return A character vector
Expand Down
4 changes: 2 additions & 2 deletions R/translate.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#' Resolve a Model Specification for a Computational Engine
#'
#' `translate()` will translate a model specification into a code
#' `translate()` will translate a [model specification][model_spec] into a code
#' object that is specific to a particular engine (e.g. R package).
#' It translates generic parameters to their counterparts.
#'
#' @param x A model specification.
#' @param x A [model specification][model_spec].
#' @param engine The computational engine for the model (see `?set_engine`).
#' @param ... Not currently used.
#' @details
Expand Down
2 changes: 1 addition & 1 deletion R/update.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#' @inheritParams svm_linear
#' @inheritParams svm_poly
#' @inheritParams svm_rbf
#' @param object A model specification.
#' @param object A [model specification][model_spec].
#' @param parameters A 1-row tibble or named list with _main_
#' parameters to update. Use **either** `parameters` **or** the main arguments
#' directly when updating. If the main arguments are used,
Expand Down
2 changes: 1 addition & 1 deletion man/augment.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/case_weights_allowed.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/convert_helpers.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/eval_args.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/extract-parsnip.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions man/model_fit.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 26 additions & 3 deletions man/model_spec.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/multi_predict.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/other_predict.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/parsnip_update.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/predict.model_fit.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/req_pkgs.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/required_pkgs.model_spec.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/set_args.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading