Skip to content

Unable to tune penalty for glmnet with non-default family #738

Closed
@cb12991

Description

@cb12991

The problem

I'm unable to tune the penalty hyperparameter for a glmnet model specification with non-default family engine argument. I've traced the error down to the multi_predict generic not having a method for generalized model fits (class _glmnetfit).

I have also tried passing specific path_values as an engine argument (which I think will need to be done to correctly compare penalty values) but that didn't resolve the underlying issue with multi_predict.

Reproducible example

library(tidyverse)
library(tidymodels)

recipe <- recipe(hp ~ ., data = mtcars)
lasso <- linear_reg(
  mixture = 1,
  penalty = !!tune()
) %>% 
  set_engine(
    engine = 'glmnet',
    family = gaussian(link = 'log')
  )
wflow <- workflow(recipe, lasso)
grid <- grid_max_entropy(penalty(), size = 10)
folds <- vfold_cv(mtcars)

res <- tune_grid(
  object = wflow,
  resamples = folds,
  grid = grid
)
#> x Fold01: preprocessor 1/1, model 1/1 (predictions): Error in `parsnip::multi_pred...
#> x Fold02: preprocessor 1/1, model 1/1 (predictions): Error in `parsnip::multi_pred...
#> x Fold03: preprocessor 1/1, model 1/1 (predictions): Error in `parsnip::multi_pred...
#> x Fold04: preprocessor 1/1, model 1/1 (predictions): Error in `parsnip::multi_pred...
#> x Fold05: preprocessor 1/1, model 1/1 (predictions): Error in `parsnip::multi_pred...
#> x Fold06: preprocessor 1/1, model 1/1 (predictions): Error in `parsnip::multi_pred...
#> x Fold07: preprocessor 1/1, model 1/1 (predictions): Error in `parsnip::multi_pred...
#> x Fold08: preprocessor 1/1, model 1/1 (predictions): Error in `parsnip::multi_pred...
#> x Fold09: preprocessor 1/1, model 1/1 (predictions): Error in `parsnip::multi_pred...
#> x Fold10: preprocessor 1/1, model 1/1 (predictions): Error in `parsnip::multi_pred...
#> Warning: All models failed. See the `.notes` column.

res %>% collect_notes %>% distinct(note) %>% reduce(c) %>% cli::cli_ul()
#> • Error in `parsnip::multi_predict()`: ! No `multi_predict` method exists for
#> objects with classes '_glmnetfit', 'model_fit'

Created on 2022-05-31 by the reprex package (v2.0.1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions