svm_linear() is a way to generate a specification of a model before fitting and allows the model to be created using different packages in R or via Spark. The main arguments for the model are:

  • cost: The cost of predicting a sample within or on the wrong side of the margin.

  • margin: The epsilon in the SVM insensitive loss function (regression only)

These arguments are converted to their specific names at the time that the model is fit. Other options and arguments can be set using set_engine(). If left to their defaults here (NULL), the values are taken from the underlying model functions. If parameters need to be modified, update() can be used in lieu of recreating the object from scratch.

svm_linear(mode = "unknown", cost = NULL, margin = NULL)

# S3 method for svm_linear
update(
  object,
  parameters = NULL,
  cost = NULL,
  margin = NULL,
  fresh = FALSE,
  ...
)

Arguments

mode

A single character string for the type of model. Possible values for this model are "unknown", "regression", or "classification".

cost

A positive number for the cost of predicting a sample within or on the wrong side of the margin

margin

A positive number for the epsilon in the SVM insensitive loss function (regression only)

object

A linear SVM model specification.

parameters

A 1-row tibble or named list with main parameters to update. If the individual arguments are used, these will supersede the values in parameters. Also, using engine arguments in this object will result in an error.

fresh

A logical for whether the arguments should be modified in-place of or replaced wholesale.

...

Not used for update().

Details

The model can be created using the fit() function using the following engines:

  • R: "LiblineaR" (the default)

Engine Details

Engines may have pre-set default arguments when executing the model fit call. For this type of model, the template of the fit calls are below:

LiblineaR

svm_linear() %>% 
  set_engine("LiblineaR") %>% 
  set_mode("regression") %>% 
  translate()

## Linear Support Vector Machine Specification (regression)
## 
## Computational engine: LiblineaR 
## 
## Model fit template:
## LiblineaR::LiblineaR(x = missing_arg(), y = missing_arg(), wi = missing_arg(), 
##     type = 11, svr_eps = 0.1)

svm_linear() %>% 
  set_engine("LiblineaR") %>% 
  set_mode("classification") %>% 
  translate()

## Linear Support Vector Machine Specification (classification)
## 
## Computational engine: LiblineaR 
## 
## Model fit template:
## LiblineaR::LiblineaR(x = missing_arg(), y = missing_arg(), wi = missing_arg(), 
##     type = 1)

Note that the LiblineaR engine cannot produce class probabilities. When optimizing the model using the tune package, the default metrics require class probabilities. To be able to use the tune_*() functions, a metric set must be passed as an argument and it can only contain metrics associated with hard class predictions (e.g., accuracy and so on).

This engine fits models that are L2-regularized for L2-loss. In the LiblineaR documentation, these are types 1 (classification) and 11 (regression).

Parameter translations

The standardized parameter names in parsnip can be mapped to their original names in each engine that has main parameters. Each engine typically has a different default value (shown in parentheses) for each parameter.

parsnipLiblineaR
costC (1)
marginsvr_eps (0.1)

See also

Examples

show_engines("svm_linear")
#> # A tibble: 2 x 2 #> engine mode #> <chr> <chr> #> 1 LiblineaR classification #> 2 LiblineaR regression
svm_linear(mode = "classification")
#> Linear Support Vector Machine Specification (classification) #>
# Parameters can be represented by a placeholder: svm_linear(mode = "regression", cost = varying())
#> Linear Support Vector Machine Specification (regression) #> #> Main Arguments: #> cost = varying() #>
model <- svm_linear(cost = 3) model
#> Linear Support Vector Machine Specification (unknown) #> #> Main Arguments: #> cost = 3 #>
update(model, cost = 1)
#> Linear Support Vector Machine Specification (unknown) #> #> Main Arguments: #> cost = 1 #>
update(model, cost = 1, fresh = TRUE)
#> Linear Support Vector Machine Specification (unknown) #> #> Main Arguments: #> cost = 1 #>