diff --git a/DESCRIPTION b/DESCRIPTION index 6094f3d09..4834eb6ee 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -50,4 +50,5 @@ Suggests: rpart, MASS, nlme, - modeldata + modeldata, + liquidSVM diff --git a/NEWS.md b/NEWS.md index 4243b7deb..611b26bfa 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,10 +1,18 @@ # parsnip 0.1.1 +## New Features + + * `liquidSVM` was added as an engine for `svm_rbf()` (#300) + +## Fixes + +* The error message for missing packages was fixed (#289 and #292) + + ## Other Changes * S3 dispatch for `tidy()` was broken on R 4.0. -* The error message for missing packages was fixed (#289 and #292) # parsnip 0.0.5 diff --git a/R/svm_rbf.R b/R/svm_rbf.R index d6979c098..a2568e21e 100644 --- a/R/svm_rbf.R +++ b/R/svm_rbf.R @@ -36,11 +36,6 @@ #' \item \pkg{R}: `"liquidSVM"` #' } #' -#' Note that models created using the `liquidSVM` engine cannot be saved like -#' conventional R objects. The `fit` slot of the `model_fit` object has to be -#' saved separately using the `liquidSVM::write.liquidSVM()` function. Likewise -#' to restore a model, the `fit` slot has to be replaced with the model that is -#' read using the `liquidSVM::read.liquidSVM()` function. #' #' @includeRmd man/rmd/svm-rbf.Rmd details #' diff --git a/R/svm_rbf_data.R b/R/svm_rbf_data.R index 1f7ffdb3a..ae58c6db6 100644 --- a/R/svm_rbf_data.R +++ b/R/svm_rbf_data.R @@ -243,9 +243,12 @@ set_pred( type = "prob", value = list( pre = function(x, object) { - if (object$fit$predict.prob == FALSE) - stop("`svm` model does not appear to use class probabilities. Was ", - "the model fit with `predict.prob = TRUE`?", call. = FALSE) + if (!object$fit$predict.prob) { + rlang::abort( + paste0("`svm` model does not appear to use class probabilities. Was ", + "the model fit with `predict.prob = TRUE`?") + ) + } x }, post = function(result, object) { diff --git a/man/rmd/svm-rbf.Rmd b/man/rmd/svm-rbf.Rmd index 3bae62035..d4e194d4e 100644 --- a/man/rmd/svm-rbf.Rmd +++ b/man/rmd/svm-rbf.Rmd @@ -19,6 +19,32 @@ svm_rbf() %>% translate() ``` +## liquidSVM + +```{r liquidSVM-reg} +svm_rbf() %>% + set_engine("liquidSVM") %>% + set_mode("regression") %>% + translate() +``` + +```{r liquidSVM-cls} +svm_rbf() %>% + set_engine("liquidSVM") %>% + set_mode("classification") %>% + translate() +``` + +Note that models created using the `liquidSVM` engine cannot be saved like +conventional R objects. The `fit` slot of the `model_fit` object has to be saved +separately using the `liquidSVM::write.liquidSVM()` function. Likewise to restore +a model, the `fit` slot has to be replaced with the model that is read using the +`liquidSVM::read.liquidSVM()` function. + +`liquidSVM` parameterizes the kernel parameter differently than `kernlab`. To +translate between engines, `sigma = 1/gammas^2`. Users will be specifying +`sigma` and the function translates the value to `gamma`. + ## Parameter translations The standardized parameter names in parsnip can be mapped to their original diff --git a/man/svm_rbf.Rd b/man/svm_rbf.Rd index 8dba5c6a3..6d605fda2 100644 --- a/man/svm_rbf.Rd +++ b/man/svm_rbf.Rd @@ -67,6 +67,7 @@ The model can be created using the \code{fit()} function using the following \emph{engines}: \itemize{ \item \pkg{R}: \code{"kernlab"} (the default) +\item \pkg{R}: \code{"liquidSVM"} } } \section{Engine Details}{ @@ -96,14 +97,51 @@ call. For this type of model, the template of the fit calls are below: } } +\subsection{liquidSVM}{\if{html}{\out{
}}\preformatted{svm_rbf() \%>\% + set_engine("liquidSVM") \%>\% + set_mode("regression") \%>\% + translate() +}\if{html}{\out{
}}\preformatted{## Radial Basis Function Support Vector Machine Specification (regression) +## +## Computational engine: liquidSVM +## +## Model fit template: +## liquidSVM::svm(x = missing_arg(), y = missing_arg(), folds = 1, +## threads = 0) +}\if{html}{\out{
}}\preformatted{svm_rbf() \%>\% + set_engine("liquidSVM") \%>\% + set_mode("classification") \%>\% + translate() +}\if{html}{\out{
}}\preformatted{## Radial Basis Function Support Vector Machine Specification (classification) +## +## Computational engine: liquidSVM +## +## Model fit template: +## liquidSVM::svm(x = missing_arg(), y = missing_arg(), folds = 1, +## threads = 0) +} + +Note that models created using the \code{liquidSVM} engine cannot be saved +like conventional R objects. The \code{fit} slot of the \code{model_fit} object +has to be saved separately using the \code{liquidSVM::write.liquidSVM()} +function. Likewise to restore a model, the \code{fit} slot has to be replaced +with the model that is read using the \code{liquidSVM::read.liquidSVM()} +function. + +\code{liquidSVM} parameterizes the kernel parameter differently than +\code{kernlab}. To translate between engines, \code{sigma = 1/gammas^2}. Users +will be specifying \code{sigma} and the function translates the value to +\code{gamma}. +} + \subsection{Parameter translations}{ The standardized parameter names in parsnip can be mapped to their -original names in each engine that has main parameters:\tabular{ll}{ - \strong{parsnip} \tab \strong{kernlab} \cr - cost \tab C \cr - rbf_sigma \tab sigma \cr - margin \tab epsilon \cr +original names in each engine that has main parameters:\tabular{lll}{ + \strong{parsnip} \tab \strong{kernlab} \tab \strong{liquidSVM} \cr + cost \tab C \tab lambdas \cr + rbf_sigma \tab sigma \tab gammas \cr + margin \tab epsilon \tab NA \cr } }