Skip to content

Add tidy method for LiblineaR parsnip models #474

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

Merged
merged 3 commits into from
Apr 22, 2021
Merged

Add tidy method for LiblineaR parsnip models #474

merged 3 commits into from
Apr 22, 2021

Conversation

juliasilge
Copy link
Member

This PR adds a tidy method for LiblineaR models trained with parsnip:

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

data(two_class_dat, package = "modeldata")
example_split <- initial_split(two_class_dat, prop = 0.99)
example_train <- training(example_split)
example_test  <-  testing(example_split)

rec <- recipe(Class ~ ., data = example_train) %>%
  step_normalize(all_numeric_predictors())

spec1 <- svm_linear() %>%
  set_engine("LiblineaR") %>%
  set_mode("classification")

spec2 <- logistic_reg(penalty = 0.1, mixture = 1) %>%
  set_engine("LiblineaR") %>%
  set_mode("classification")

wf <- workflow() %>%
  add_recipe(rec)

wf %>%
  add_model(spec1) %>% 
  fit(example_train) %>%
  tidy()
#> # A tibble: 3 x 2
#>   term  estimate
#>   <chr>    <dbl>
#> 1 A        0.367
#> 2 B       -0.964
#> 3 Bias     0.118

wf %>%
  add_model(spec2) %>% 
  fit(example_train) %>%
  tidy()
#> # A tibble: 3 x 2
#>   term  estimate
#>   <chr>    <dbl>
#> 1 A        1.11 
#> 2 B       -2.78 
#> 3 Bias     0.349

svm_linear() %>%
  set_engine("LiblineaR") %>%
  set_mode("regression") %>% 
  fit(mpg ~ ., data = mtcars) %>% 
  tidy()
#> # A tibble: 11 x 2
#>    term  estimate
#>    <chr>    <dbl>
#>  1 cyl    0.141  
#>  2 disp  -0.0380 
#>  3 hp     0.0415 
#>  4 drat   0.226  
#>  5 wt     0.0757 
#>  6 qsec   1.06   
#>  7 vs     0.0648 
#>  8 am     0.0479 
#>  9 gear   0.219  
#> 10 carb   0.00861
#> 11 Bias   0.0525

Created on 2021-04-21 by the reprex package (v2.0.0)

@juliasilge
Copy link
Member Author

This PR will let us move a function out of _common.R for https://smltar.com/, which it looks like it is about the right time to do.

@juliasilge juliasilge requested a review from topepo April 21, 2021 21:27
@topepo topepo merged commit ecb2a8e into master Apr 22, 2021
@topepo topepo deleted the liblinear-tidy branch April 22, 2021 18:04
@github-actions
Copy link

github-actions bot commented May 7, 2021

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 May 7, 2021
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.

2 participants