Skip to content

Conversation

@topepo
Copy link
Member

@topepo topepo commented Feb 2, 2022

Closes #642

Tests will be in extratests.

Example:

library(tidymodels)
#> Registered S3 method overwritten by 'tune':
#>   method                   from   
#>   required_pkgs.model_spec parsnip
#> Warning: package 'broom' was built under R version 4.1.2
tidymodels_prefer()
theme_set(theme_bw())

data(meats)
meats <- meats %>% select(-protein, -fat)

glmn_spec <- 
 linear_reg(penalty = 0.1) %>% 
  set_engine("glmnet")
rec <- 
  recipe(water ~ ., data = meats) %>% 
  step_normalize(all_predictors())

glmn_fit <- 
  workflow(rec, glmn_spec) %>% 
  fit(meats)
  
autoplot(glmn_fit)

autoplot(glmn_fit, min_penalty = 0.01, top_n = 2)

Created on 2022-02-01 by the reprex package (v2.0.1)

@EmilHvitfeldt
Copy link
Member

I know it would require a bit more work. But what about showing the labels on the dotted line when best_penalty is specified? Something like this?

Screen Shot 2022-02-01 at 8 28 12 PM

@EmilHvitfeldt
Copy link
Member

Added a commit to have labels follow best_penalty line

library(tidymodels)
tidymodels_prefer()
theme_set(theme_bw())

data(meats)
meats <- meats %>% select(-protein, -fat)

glmn_spec <- 
  linear_reg(penalty = 0.1) %>% 
  set_engine("glmnet")
rec <- 
  recipe(water ~ ., data = meats) %>% 
  step_normalize(all_predictors())

glmn_fit <- 
  workflow(rec, glmn_spec) %>% 
  fit(meats)

autoplot(glmn_fit)

autoplot(glmn_fit, best_penalty = 0.033)

autoplot(glmn_fit, best_penalty = 0.6)

Created on 2022-02-08 by the reprex package (v2.0.1)

@juliasilge
Copy link
Member

I fixed the broken GH actions in a previous PR if you want to merge from main.

@topepo topepo merged commit e9abdf5 into main Feb 17, 2022
@topepo topepo deleted the glmnet-autoplot branch February 17, 2022 00:52
@github-actions
Copy link
Contributor

github-actions bot commented Mar 4, 2022

This pull request has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.

@github-actions github-actions bot locked and limited conversation to collaborators Mar 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

proper glmnet autoplot method

5 participants