forked from tidymodels/parsnip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen_additive_mod.R
106 lines (93 loc) · 2.8 KB
/
gen_additive_mod.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#' Generalized additive models (GAMs)
#'
#' @description
#' `gen_additive_mod()` defines a model that can use smoothed functions of
#' numeric predictors in a generalized linear model. This function can fit
#' classification and regression models.
#'
#' \Sexpr[stage=render,results=rd]{parsnip:::make_engine_list("gen_additive_mod")}
#'
#' More information on how \pkg{parsnip} is used for modeling is at
#' \url{https://www.tidymodels.org/}.
#'
#' @inheritParams boost_tree
#' @param select_features `TRUE` or `FALSE.` If `TRUE`, the model has the
#' ability to eliminate a predictor (via penalization). Increasing
#' `adjust_deg_free` will increase the likelihood of removing predictors.
#' @param adjust_deg_free If `select_features = TRUE`, then acts as a multiplier
#' for smoothness. Increase this beyond 1 to produce smoother models.
#'
#' @template spec-details
#'
#' @template spec-references
#'
#' @seealso \Sexpr[stage=render,results=rd]{parsnip:::make_seealso_list("gen_additive_mod")}
#'
#' @examples
#' show_engines("gen_additive_mod")
#'
#' gen_additive_mod()
#'
#' @export
gen_additive_mod <- function(mode = "unknown",
select_features = NULL,
adjust_deg_free = NULL,
engine = "mgcv") {
args <- list(
select_features = rlang::enquo(select_features),
adjust_deg_free = rlang::enquo(adjust_deg_free)
)
new_model_spec(
"gen_additive_mod",
args = args,
eng_args = NULL,
mode = mode,
method = NULL,
engine = engine
)
}
#' @export
print.gen_additive_mod <- function(x, ...) {
cat("GAM Specification (", x$mode, ")\n\n", sep = "")
model_printer(x, ...)
if(!is.null(x$method$fit$args)) {
cat("Model fit template:\n")
print(show_call(x))
}
invisible(x)
}
#' @export
#' @rdname parsnip_update
#' @inheritParams gen_additive_mod
update.gen_additive_mod <- function(object,
select_features = NULL,
adjust_deg_free = NULL,
parameters = NULL,
fresh = FALSE, ...) {
args <- list(
select_features = rlang::enquo(select_features),
adjust_deg_free = rlang::enquo(adjust_deg_free)
)
update_spec(
object = object,
parameters = parameters,
args_enquo_list = args,
fresh = fresh,
cls = "gen_additive_mod",
...
)
}
#' @export
translate.gen_additive_mod <- function(x, engine = x$engine, ...) {
if (is.null(engine)) {
message("Used `engine = 'mgcv'` for translation.")
engine <- "gam"
}
x <- translate.default(x, engine, ...)
x
}
#' @export
#' @keywords internal
fit_xy.gen_additive_mod <- function(object, ...) {
rlang::abort("`fit()` must be used with GAM models (due to its use of formulas).")
}