svms: Fit a Standard C-SVC Support Vector Machine

View source: R/svms.R

svmsR Documentation

Fit a Standard C-SVC Support Vector Machine

Description

Fits a C-SVC support vector machine with a Platt SMO solver. With two classes this uses the validated binary path. With three or more classes, the function fits one binary SVM for each class pair and predicts by majority vote. Multiclass ties are resolved by choosing the class that appears first in the factor level order.

Usage

svms(
  x,
  y,
  kernel = c("linear", "rbf", "poly"),
  cost = 1,
  gamma = NULL,
  degree = 3,
  coef0 = 1,
  tol = 0.001,
  max_passes = 10L,
  max_iter = 10000L
)

Arguments

x

Numeric matrix or data frame of predictors.

y

Response with at least two classes. In the binary path, level 1 is the negative class and level 2 is the positive class.

kernel

Kernel name: "linear", "rbf", or "poly".

cost

Positive C-SVC cost parameter.

gamma

Kernel scale. Defaults to 1 / ncol(x).

degree

Polynomial degree.

coef0

Polynomial offset.

tol

SMO tolerance.

max_passes

Maximum consecutive passes without alpha changes.

max_iter

Maximum SMO iterations.

Value

A fitted svms object for two classes, or a svms_multiclass object for three or more classes.

Examples

set.seed(1)
dat <- gen_moons(40, noise = 0.1)
fit <- svms(dat$x, dat$y, kernel = "linear", cost = 1)
predict(fit, dat$x[1:3, ])

twinsvm documentation built on June 10, 2026, 1:06 a.m.