-
Notifications
You must be signed in to change notification settings - Fork 90
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
Add kernlab engine for svm_linear() #438
Conversation
}) | ||
|
||
test_that('engine arguments', { | ||
|
||
LiblineaR_type <- svm_linear(mode = "regression") %>% set_engine("LiblineaR", type = 12) | ||
kernlab_cv <- svm_linear(mode = "regression") %>% set_engine("kernlab", cross = 10) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this cross
arg seems to do internal cross validation, using accuracy as a metric for classification. When doing binary classification, do you happen to know if it is considering the first or second level as the event level? Does that matter at all here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like it is doing the same thing as what parsnip is doing, with no problems like what xgboost had:
library(parsnip)
library(tidyverse)
library(kernlab)
#>
#> Attaching package: 'kernlab'
#> The following object is masked from 'package:purrr':
#>
#> cross
#> The following object is masked from 'package:ggplot2':
#>
#> alpha
data("PimaIndiansDiabetes", package = "mlbench")
df <- PimaIndiansDiabetes %>%
mutate(diabetes = fct_relevel(diabetes, 'pos'))
set.seed(234)
parsnip_fit <- svm_linear(mode = "classification") %>%
set_engine("kernlab", cross = 10) %>%
fit(diabetes ~ ., df)
#> Setting default kernel parameters
set.seed(234)
kernlab_fit <- ksvm(diabetes ~ ., data = df, kernel = "vanilladot", cross = 10)
#> Setting default kernel parameters
parsnip_fit
#> parsnip model object
#>
#> Fit time: 833ms
#> Support Vector Machine object of class "ksvm"
#>
#> SV type: C-svc (classification)
#> parameter : cost C = 1
#>
#> Linear (vanilla) kernel function.
#>
#> Number of Support Vectors : 401
#>
#> Objective Function Value : -396.4286
#> Training error : 0.226562
#> Cross validation error : 0.233117
#> Probability model included.
kernlab_fit
#> Support Vector Machine object of class "ksvm"
#>
#> SV type: C-svc (classification)
#> parameter : cost C = 1
#>
#> Linear (vanilla) kernel function.
#>
#> Number of Support Vectors : 401
#>
#> Objective Function Value : -396.4286
#> Training error : 0.226562
#> Cross validation error : 0.233117
identical(parsnip_fit$fit@alpha, kernlab_fit@alpha)
#> [1] TRUE
Created on 2021-03-03 by the reprex package (v1.0.0)
Created on 2021-03-03 by the reprex package (v1.0.0)
If there is a problem (I don't think there is), it would apply to all the kernlab engines and we should open a new issue and fix it in a new PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, just wanted to check
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. |
Closes #336
This PR adds a second engine for
svm_linear()
. We already have"LiblineaR"
and this PR adds"kernlab"
.Created on 2021-03-01 by the reprex package (v1.0.0)
Unlike the
"LiblineaR"
engine, the"kernlab"
engine does support class probabilities.