/
nnet.R
89 lines (81 loc) · 1.7 KB
/
nnet.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
#' Axing a nnet.
#'
#' nnet objects are created from the \pkg{nnet} package, leveraged to
#' fit multilayer perceptron models.
#'
#' @inheritParams butcher
#'
#' @return Axed nnet object.
#'
#' @examplesIf rlang::is_installed(c("parsnip", "nnet"))
#' # Load libraries
#' library(parsnip)
#' library(nnet)
#'
#' # Create and fit model
#' nnet_fit <- mlp("classification", hidden_units = 2) %>%
#' set_engine("nnet") %>%
#' fit(Species ~ ., data = iris)
#'
#' out <- butcher(nnet_fit, verbose = TRUE)
#'
#' # Another nnet object
#' targets <- class.ind(c(rep("setosa", 50),
#' rep("versicolor", 50),
#' rep("virginica", 50)))
#'
#' fit <- nnet(iris[,1:4],
#' targets,
#' size = 2,
#' rang = 0.1,
#' decay = 5e-4,
#' maxit = 20)
#'
#' out <- butcher(fit, verbose = TRUE)
#'
#' @name axe-nnet
NULL
#' Remove the call.
#'
#' @rdname axe-nnet
#' @export
axe_call.nnet <- function(x, verbose = FALSE, ...) {
old <- x
x <- exchange(x, "call", call("dummy_call"))
add_butcher_attributes(
x,
old,
verbose = verbose
)
}
#' Remove environments.
#'
#' @rdname axe-nnet
#' @export
axe_env.nnet <- function(x, verbose = FALSE, ...) {
old <- x
x$terms <- axe_env(x$terms, ...)
add_butcher_attributes(
x,
old,
verbose = verbose
)
}
#' Remove fitted values.
#'
#' @rdname axe-nnet
#' @export
axe_fitted.nnet <- function(x, verbose = FALSE, ...) {
old <- x
x <- exchange(x, "fitted.values", numeric(0))
add_butcher_attributes(
x,
old,
disabled = c(
"fitted()",
"predict() with no new data",
"dimnames(axed_object$fitted.values)"
),
verbose = verbose
)
}