Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle quasi-likelihood glmnet models better #15

Open
topepo opened this issue May 4, 2021 · 1 comment
Open

handle quasi-likelihood glmnet models better #15

topepo opened this issue May 4, 2021 · 1 comment
Labels
feature a feature request or enhancement

Comments

@topepo
Copy link
Member

topepo commented May 4, 2021

Similar to tidymodels/parsnip#483

library(tidymodels)
#> Registered S3 method overwritten by 'tune':
#>   method                   from   
#>   required_pkgs.model_spec parsnip
library(poissonreg)

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)

poisson_reg(penalty = 0.5) %>% 
  set_engine("glmnet") %>% 
  fit(y ~ x1 + x2, data = data) %>% 
  pluck("fit") %>% 
  class()
#> [1] "fishnet" "glmnet"

# 'fishnet' is their class of Poisson models

poisson_reg(penalty = 0.5) %>% 
  set_engine("glmnet", family = quasipoisson()) %>% 
  fit(y ~ x1 + x2, data = data) %>% 
  pluck("fit") %>% 
  class()
#> [1] "glmnetfit" "glmnet"

# Now the class is not Poisson specific, so our methods don't know what to do

Created on 2021-05-04 by the reprex package (v1.0.0.9000)

We should add class to the parsnip model or restrict this family for this engine.

@topepo topepo added the feature a feature request or enhancement label May 4, 2021
@hfrick
Copy link
Member

hfrick commented Jan 4, 2023

@topepo do you have a preference between the two options? I tend towards trying to avoid restricting the family but I guess that means adding running glmnet-specific code in parsnip::fit.model_spec() (in these lines) and parsnip::fit_xy.model_spec()

If we make the changes in parsnip, we might not need to touch the extension packages with glmnet engines

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants