'How to make svm_linear work with tune_grid/tune_race_anova
So when I try to tune cost for svm_linear with tidymodels approach, it fails every time, but it works just fine with svm_rbf function, so I cannot understand where the problem comes from
rcpsvm<-recipe(Species~.,data=iris)
svmlin<-svm_linear(cost=tune())%>%
set_engine("LiblineaR")%>%
set_mode("classification")
svmlinwrkfl<-workflow()%>%
add_recipe(rcpsvm)%>%
add_model(svmlin)
gridwals<-expand_grid(cost=c(0.01, 0.1, 1, 10, 100))
folds<-vfold_cv(iris, strata=Species, 5)
tunelin<-tune_grid(svmlinwrkfl, grid = gridwals, folds)
And then it says that all models failed cause No data available in table What I'm doing wrong?
Solution 1:[1]
The specific model you are using cannot generate class probabilities, only hard class predictions, so you need to tune using a metric for classes (not a metric for probabilities). An example of this is sensitivity:
library(tidymodels)
#> Registered S3 method overwritten by 'tune':
#> method from
#> required_pkgs.model_spec parsnip
data(two_class_dat)
data_train <- two_class_dat[-(1:10), ]
data_test <- two_class_dat[ 1:10 , ]
folds <- bootstraps(data_train, times = 5)
svm_cls_spec <-
svm_linear(cost = tune()) %>%
set_mode("classification") %>%
set_engine("LiblineaR")
workflow(Class ~ ., svm_cls_spec) %>%
tune_grid(folds, grid = 5, metrics = metric_set(sensitivity))
#> # Tuning results
#> # Bootstrap sampling
#> # A tibble: 5 × 4
#> splits id .metrics .notes
#> <list> <chr> <list> <list>
#> 1 <split [781/296]> Bootstrap1 <tibble [5 × 5]> <tibble [0 × 1]>
#> 2 <split [781/286]> Bootstrap2 <tibble [5 × 5]> <tibble [0 × 1]>
#> 3 <split [781/296]> Bootstrap3 <tibble [5 × 5]> <tibble [0 × 1]>
#> 4 <split [781/291]> Bootstrap4 <tibble [5 × 5]> <tibble [0 × 1]>
#> 5 <split [781/304]> Bootstrap5 <tibble [5 × 5]> <tibble [0 × 1]>
Created on 2022-01-28 by the reprex package (v2.0.1)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Julia Silge |
