Skip to content
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
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# parsnip (development version)

* `.organize_glmnet_pred()` now expects predictions for a single penalty value (#876).

# parsnip 1.0.4

* For censored regression models, a "reverse Kaplan-Meier" curve is computed for the censoring distribution. This can be used when evaluating this type of model (#855).
Expand Down
13 changes: 1 addition & 12 deletions R/linear_reg.R
Original file line number Diff line number Diff line change
Expand Up @@ -142,18 +142,7 @@ check_args.linear_reg <- function(object) {
#' @keywords internal
#' @export
.organize_glmnet_pred <- function(x, object) {
if (ncol(x) == 1) {
res <- x[, 1]
res <- unname(res)
} else {
n <- nrow(x)
res <- utils::stack(as.data.frame(x))
if (!is.null(object$spec$args$penalty))
res$lambda <- rep(object$spec$args$penalty, each = n) else
res$lambda <- rep(object$fit$lambda, each = n)
res <- res[, colnames(res) %in% c("values", "lambda")]
}
res
unname(x[, 1])
}

#' @export
Expand Down
28 changes: 3 additions & 25 deletions R/logistic_reg.R
Original file line number Diff line number Diff line change
Expand Up @@ -174,35 +174,13 @@ prob_to_class_2 <- function(x, object) {
unname(x)
}


organize_glmnet_class <- function(x, object) {
if (ncol(x) == 1) {
res <- prob_to_class_2(x[, 1], object)
} else {
n <- nrow(x)
res <- utils::stack(as.data.frame(x))
res$values <- prob_to_class_2(res$values, object)
if (!is.null(object$spec$args$penalty))
res$lambda <- rep(object$spec$args$penalty, each = n) else
res$lambda <- rep(object$fit$lambda, each = n)
res <- res[, colnames(res) %in% c("values", "lambda")]
}
res
prob_to_class_2(x[, 1], object)
}

organize_glmnet_prob <- function(x, object) {
if (ncol(x) == 1) {
res <- tibble(v1 = 1 - x[, 1], v2 = x[, 1])
colnames(res) <- object$lvl
} else {
n <- nrow(x)
res <- utils::stack(as.data.frame(x))
res <- tibble(v1 = 1 - res$values, v2 = res$values)
colnames(res) <- object$lvl
if (!is.null(object$spec$args$penalty))
res$lambda <- rep(object$spec$args$penalty, each = n) else
res$lambda <- rep(object$fit$lambda, each = n)
}
res <- tibble(v1 = 1 - x[, 1], v2 = x[, 1])
colnames(res) <- object$lvl
res
}

Expand Down