0

I have fitted text data based on regression and LiblineaR engine. And I want to `tidy()` my results. I have also installed the dev version of `broom`. But I always get an error. `ERROR: No tidy method for objects of class LiblineaR`
> svm_fit %>%
+   pull_workflow_fit() %>%
+   tidy()
ERROR: No tidy method for objects of class LiblineaR
Christian
  • 401
  • 1
  • 5
  • 14
  • The error indiocates that the authors of `broom` haven't written a `tidy()` function for the `LiblineaR` class. You can ask them to do it, you can ask the authors of the package that creates `LiblineaR` objects, or you can write one yourself. It shouldn't be difficult. Without knowing your input data and your desired output, it's difficult to give you more concrete advice. – Limey Apr 20 '21 at 13:17
  • I assume you are working through the code in smltar.com. We wrote tidy.LiblineaR https://github.com/EmilHvitfeldt/smltar/blob/master/_common.R#L143-L149, it will be added soon to the appropriate package before the book is released – EmilHvitfeldt Apr 20 '21 at 20:39
  • yes that is correct. Thank you for the hint. – Christian Apr 22 '21 at 12:25

1 Answers1

1

We just merged in support for the tidy() method for parsnip models fitted with the LiblineaR engine, so if you install from GitHub, you should be able to have this feature now:

devtools::install_github("tidymodels/parsnip")

Here is a demo of how it works:

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.361
#> 2 B       -0.966
#> 3 Bias     0.113

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

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-22 by the reprex package (v2.0.0)

Julia Silge
  • 10,848
  • 2
  • 40
  • 48