Skip to content

Fits a support vector regression or classification on a 'tidyFit' R6 class. The function can be used with regress or classify.

Usage

# S3 method for svm
.fit(self, data = NULL)

Arguments

self

a 'tidyFit' R6 class.

data

a data frame, data frame extension (e.g. a tibble), or a lazy data frame (e.g. from dbplyr or dtplyr).

Value

A fitted 'tidyFit' class model.

Details

Hyperparameters:

  • cost (cost of constraint violation)

  • epsilon (epsilon in the insensitive-loss function)

Important method arguments (passed to m)

The function provides a wrapper for e1071::svm. See ?svm for more details.

Implementation

The default value for the kernel argument is set to 'linear'. If set to a different value, no coefficients will be returned.

References

Meyer D, Dimitriadou E, Hornik K, Weingessel A, Leisch F (2022). e1071: Misc Functions of the Department of Statistics, Probability Theory Group (Formerly: E1071), TU Wien. R package version 1.7-12, https://CRAN.R-project.org/package=e1071.

See also

.fit.boost, .fit.lasso and m methods

Author

Johann Pfitzinger

Examples

# Load data
data <- tidyfit::Factor_Industry_Returns
data <- dplyr::filter(data, Industry == "HiTec")

# Stand-alone function
fit <- m("svm", Return ~ `Mkt-RF` + HML + SMB, data, cost = 0.1)
fit
#> # A tibble: 1 × 6
#>   estimator_fct `size (MB)` grid_id  model_object settings         errors 
#>   <chr>               <dbl> <chr>    <list>       <list>           <chr>  
#> 1 e1071::svm              0 #0010000 <tidyFit>    <tibble [1 × 3]> object…

# Within 'regress' function
fit <- regress(data, Return ~ ., m("svm", cost = 0.1),
               .mask = c("Date", "Industry"))
coef(fit)
#> # A tibble: 7 × 4
#> # Groups:   model [1]
#>   model term        estimate model_info      
#>   <chr> <chr>          <dbl> <list>          
#> 1 svm   (Intercept)   0.592  <tibble [1 × 0]>
#> 2 svm   Mkt-RF        1.05   <tibble [1 × 0]>
#> 3 svm   SMB           0.0812 <tibble [1 × 0]>
#> 4 svm   HML          -0.332  <tibble [1 × 0]>
#> 5 svm   RMW          -0.300  <tibble [1 × 0]>
#> 6 svm   CMA          -0.472  <tibble [1 × 0]>
#> 7 svm   RF            0.281  <tibble [1 × 0]>