Skip to content

wrong penalty checking in get_glmnet_coefs() #1261

Closed
@EmilHvitfeldt

Description

@EmilHvitfeldt

When trying to rerender https://www.tidymodels.org/learn/models/coefficients/ in tidymodels/tidymodels.org#92, i found the following bug in get_glmnet_coefs(). Below is a reprex

library(tidymodels)
data(Chicago)

Chicago <- Chicago %>% select(ridership, Clark_Lake, Austin, Harlem)

glmnet_spec <- 
  linear_reg(penalty = 0.1, mixture = 0.95) %>% 
  set_engine("glmnet")

glmnet_wflow <- 
  workflow() %>% 
  add_model(glmnet_spec) %>% 
  add_formula(ridership ~ .)

glmnet_fit <- fit(glmnet_wflow, Chicago)

tidy(glmnet_fit, penalty = 5.5620)
#> 
#> Attaching package: 'Matrix'
#> The following objects are masked from 'package:tidyr':
#> 
#>     expand, pack, unpack
#> Loaded glmnet 4.1-8
#> Error in `tidy()`:
#> ! `penalty` must be a number between 0 and 1 or `NULL`, not the number 5.56.

Created on 2025-03-07 with reprex v2.1.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