Error when using multi_predict() with glmnet

I receive an error when I try to use multi_predict() with a glmnet model. The error is

Error in class(): 0 arguments passed to 'class' which requires 1

Below is a reprex.


``` r
library(tidymodels)
library(poissonreg)

# synthesized data ----
n <- 2e3
set.seed(123)
x1 <- MASS::rnegbin(n, mu = 28, theta = 0.6)
x2 <- rnorm(n, 5, 10)
x3 <- as.factor(rnorm(n) < 0)
y <- as.integer(x1 + x2 + as.numeric(x3))
y[y < 0] <- 0
data <- tibble(y, x1, x2, x3)

# recipe
rec <- recipe(y ~ ., data = data) %>% 
  step_dummy(all_nominal()) %>% 
  step_normalize(all_predictors())

# glmnet spec
pois_spec <- poisson_reg() %>% 
  set_engine("glmnet")

# wflow
wflow <- workflow() %>% 
  add_recipe(rec) %>% 
  add_model(pois_spec)

# fit workflow
wflow_fit <- wflow %>% 
  fit(data = data)

# predict
preds <- predict(wflow_fit, data, penalty = 0.5)
str(preds)
#> tibble [2,000 × 1] (S3: tbl_df/tbl/data.frame)
#>  $ .pred: num [1:2000] 21.7 86.5 14 25 22.8 ...

# multi_predict also gives an error
preds <- multi_predict(wflow_fit, data, penalty = c(0.550, 0.604))
#> Error in class(): 0 arguments passed to 'class' which requires 1

Created on 2021-05-01 by the reprex package (v1.0.0)

It's a bug (discussed in a different post).

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.