Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
10 changes: 10 additions & 0 deletions R/glmnet-engines.R
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,16 @@ predict_raw._glmnetfit <- predict_raw_glmnet
unname(x[, 1])
}

organize_glmnet_pre_pred <- function(x, object) {
x <- x[, rownames(object$fit$beta), drop = FALSE]
if (is_sparse_matrix(x)) {
return(x)
}

as.matrix(x)
}


organize_glmnet_class <- function(x, object) {
prob_to_class_2(x[, 1], object)
}
Expand Down
2 changes: 1 addition & 1 deletion R/linear_reg_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ set_pred(
args =
list(
object = expr(object$fit),
newx = expr(as.matrix(new_data[, rownames(object$fit$beta), drop = FALSE])),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

before we would call as.matrix() on anything before passing it to the predict method for the engine.

However if the data is a sparse matrix, we don't want to do that as {glmnet} is happy to receive it

newx = expr(organize_glmnet_pre_pred(new_data, object)),
type = "response",
s = expr(object$spec$args$penalty)
)
Expand Down
Loading