Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Imports:
tibble (>= 2.1.1),
generics (>= 0.1.0),
glue,
lifecycle,
magrittr,
stats,
tidyr (>= 1.0.0),
Expand Down Expand Up @@ -51,5 +52,4 @@ Suggests:
MASS,
nlme,
modeldata,
liquidSVM,
Matrix
6 changes: 5 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# parsnip (development version)

* The `liquidSVM` engine for `svm_rbf()` was deprecated due to that package's removal from CRAN.

# parsnip 0.1.5

* An RStudio add-in is availble that makes writing multiple `parsnip` model specifications to the source window. It can be accessed via the IDE addin menus or by calling `parsnip_addin()`.
* An RStudio add-in is available that makes writing multiple `parsnip` model specifications to the source window. It can be accessed via the IDE addin menus or by calling `parsnip_addin()`.

* For `xgboost` models, users can now pass `objective` to `set_engine("xgboost")`. (#403)

Expand Down
6 changes: 6 additions & 0 deletions R/engines.R
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ set_engine <- function(object, engine, ...) {
}
if (!is.character(engine) | length(engine) != 1)
rlang::abort("`engine` should be a single character value.")
if (engine == "liquidSVM") {
lifecycle::deprecate_soft(
"0.1.6",
"set_engine(engine = 'cannot be liquidSVM')",
details = "The liquidSVM package is no longer available on CRAN.")
}

object$engine <- engine
object <- check_engine(object)
Expand Down
1 change: 0 additions & 1 deletion R/svm_rbf.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#' following _engines_:
#' \itemize{
#' \item \pkg{R}: `"kernlab"` (the default)
#' \item \pkg{R}: `"liquidSVM"`
#' }
#'
#'
Expand Down
30 changes: 0 additions & 30 deletions man/rmd/svm-rbf.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,6 @@ svm_rbf() %>%

`fit()` passes the data directly to `kernlab::ksvm()` so that its formula method can create dummy variables as-needed.

## 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`.

`fit()` passes the data directly to `liquidSVM::svm()` so that its formula method can create dummy variables as-needed.

## Parameter translations

The standardized parameter names in parsnip can be mapped to their original
Expand All @@ -66,8 +38,6 @@ get_defaults_svm_rbf <- function() {
"svm_rbf", "kernlab", "cost", "C", "1",
"svm_rbf", "kernlab", "rbf_sigma", "sigma", "varies",
"svm_rbf", "kernlab", "margin", "epsilon", "0.1",
"svm_rbf", "liquidSVM", "cost", "lambdas", "varies",
"svm_rbf", "liquidSVM", "rbf_sigma", "gammas", "varies",
)
}
convert_args("svm_rbf")
Expand Down
45 changes: 2 additions & 43 deletions man/svm_rbf.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

129 changes: 0 additions & 129 deletions tests/testthat/test_svm_liquidsvm.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,132 +79,3 @@ test_that('bad input', {
expect_error(svm_rbf(mode = "reallyunknown"))
expect_error(translate(svm_rbf() %>% set_engine( NULL)))
})

# ------------------------------------------------------------------------------
# define model specification for classification and regression

reg_mod <-
svm_rbf(rbf_sigma = .1, cost = 0.25) %>%
set_engine("liquidSVM", random_seed = 1234, folds = 1, max_gamma=500) %>%
set_mode("regression")

cls_mod <-
svm_rbf(rbf_sigma = .1, cost = 0.125) %>%
set_engine("liquidSVM", random_seed = 1234, folds = 1) %>%
set_mode("classification")

ctrl <- fit_control(verbosity = 0, catch = FALSE)

# ------------------------------------------------------------------------------

test_that('svm rbf regression', {

skip_if_not_installed("liquidSVM")

expect_warning(
expect_error(
fit_xy(
reg_mod,
control = ctrl,
x = hpc[, 2:4],
y = hpc$compounds
),
regexp = NA
)
)

expect_warning(
expect_error(
fit(
reg_mod,
compounds ~ .,
data = hpc[, -5],
control = ctrl
),
regexp = NA
)
)

})


test_that('svm rbf regression prediction', {

skip_if_not_installed("liquidSVM")

expect_warning(
reg_form <-
fit(
object = reg_mod,
formula = compounds ~ .,
data = hpc[, -5],
control = ctrl
)
)

expect_warning(
reg_xy_form <-
fit_xy(
object = reg_mod,
x = hpc[, 2:4],
y = hpc$compounds,
control = ctrl
)
)
expect_equal(reg_form$spec, reg_xy_form$spec)

expect_warning(
liquidSVM_form <-
liquidSVM::svm(
x = compounds ~ .,
y = hpc[, -5],
gammas = .1,
lambdas = 0.25,
folds = 1,
random_seed = 1234
)
)

expect_warning(
liquidSVM_xy_form <-
liquidSVM::svm(
x = hpc[, 2:4],
y = hpc$compounds,
gammas = .1,
lambdas = 0.25,
folds = 1,
random_seed = 1234
)
)

# check coeffs for liquidSVM formula and liquidSVM xy fit interfaces
expect_equal(liquidSVM::getSolution(liquidSVM_form)[c("coeff", "sv")],
liquidSVM::getSolution(liquidSVM_xy_form)[c("coeff", "sv")])

# check predictions for liquidSVM formula and liquidSVM xy interfaces
liquidSVM_form_preds <- predict(liquidSVM_form, hpc[1:3, 2:4])
liquidSVM_form_xy_preds <- predict(liquidSVM_xy_form, hpc[1:3, 2:4])
expect_equal(liquidSVM_form_preds, liquidSVM_form_xy_preds)

# check predictions for parsnip formula and liquidSVM formula interfaces
liquidSVM_pred <-
structure(
list(.pred = liquidSVM_form_preds),
row.names = c(NA, -3L), class = c("tbl_df", "tbl", "data.frame"))

parsnip_pred <- predict(reg_form, hpc[1:3, 2:4])
expect_equal(as.data.frame(liquidSVM_pred), as.data.frame(parsnip_pred))

# check that coeffs are equal for formula methods called via parsnip and liquidSVM
expect_equal(liquidSVM::getSolution(reg_form$fit)[c("coeff", "sv")],
liquidSVM::getSolution(liquidSVM_form)[c("coeff", "sv")])

# check coeffs are equivalent for parsnip fit_xy and parsnip formula methods
expect_equal(liquidSVM::getSolution(reg_form$fit)[c("coeff", "sv")],
liquidSVM::getSolution(reg_xy_form$fit)[c("coeff", "sv")])

# check predictions are equal for parsnip xy and liquidSVM xy methods
parsnip_xy_pred <- predict(reg_xy_form, hpc[1:3, -c(1, 5)])
expect_equal(as.data.frame(liquidSVM_pred), as.data.frame(parsnip_xy_pred))
})