Skip to content

Commit bdd1d86

Browse files
committed
proposed change for glmnet models
1 parent 7571ff9 commit bdd1d86

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

R/linear_reg.R

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,23 @@ print.linear_reg <- function(x, ...) {
138138
invisible(x)
139139
}
140140

141+
142+
#' @export
143+
translate.linear_reg <- function(x, engine = x$engine, ...) {
144+
x <- translate.default(x, engine, ...)
145+
146+
if (engine == "glmnet") {
147+
# See discussion in https://github.com/tidymodels/parsnip/issues/195
148+
x$method$fit$args$lambda <- NULL
149+
# Since the `fit` infomration is gone for the penalty, we need to have an
150+
# evaludated value for the parameter.
151+
x$args$penalty <- rlang::eval_tidy(x$args$penalty)
152+
}
153+
154+
x
155+
}
156+
157+
141158
# ------------------------------------------------------------------------------
142159

143160
#' @inheritParams update.boost_tree
@@ -274,6 +291,11 @@ predict._elnet <-
274291
if (any(names(enquos(...)) == "newdata"))
275292
stop("Did you mean to use `new_data` instead of `newdata`?", call. = FALSE)
276293

294+
# See discussion in https://github.com/tidymodels/parsnip/issues/195
295+
if (is.null(penalty) & !is.null(object$spec$args$penalty)) {
296+
penalty <- object$spec$args$penalty
297+
}
298+
277299
object$spec$args$penalty <- check_penalty(penalty, object, multi)
278300

279301
object$spec <- eval_args(object$spec)

0 commit comments

Comments
 (0)