gensvm: Fit the GenSVM model

View source: R/gensvm.R

gensvmR Documentation

Fit the GenSVM model

Description

Fits the Generalized Multiclass Support Vector Machine model with the given parameters. See the package documentation (gensvm-package) for more general information about GenSVM.

Usage

gensvm(
  x,
  y,
  p = 1,
  lambda = 1e-08,
  kappa = 0,
  epsilon = 1e-06,
  weights = "unit",
  kernel = "linear",
  gamma = "auto",
  coef = 1,
  degree = 2,
  kernel.eigen.cutoff = 1e-08,
  verbose = FALSE,
  random.seed = NULL,
  max.iter = 1e+08,
  seed.V = NULL
)

Arguments

x

data matrix with the predictors.

Note that for SVMs categorical features should be converted to binary dummy features. This can be done with using the model.matrix function (i.e. model.matrix( ~ var - 1)).

y

class labels

p

parameter for the L_p norm of the loss function (1.0 <= p <= 2.0)

lambda

regularization parameter for the loss function (lambda > 0)

kappa

parameter for the hinge function in the loss function (kappa > -1.0)

epsilon

Stopping parameter for the optimization algorithm. The optimization will stop if the relative change in the loss function is below this value.

weights

type or vector of instance weights to use. Options are 'unit' for unit weights and 'group' for group size correction weights (eq. 4 in the paper). Alternatively, a vector of weights can be provided.

kernel

the kernel type to use in the classifier. It must be one of 'linear', 'poly', 'rbf', or 'sigmoid'. See the section "Kernels in GenSVM" in gensvm-package for more info.

gamma

kernel parameter for the rbf, polynomial, and sigmoid kernel. If gamma is 'auto', then 1/n_features will be used.

coef

parameter for the polynomial and sigmoid kernel.

degree

parameter for the polynomial kernel

kernel.eigen.cutoff

Cutoff point for the reduced eigendecomposition used with kernel-GenSVM. Eigenvectors for which the ratio between their corresponding eigenvalue and the largest eigenvalue is smaller than this cutoff value will be dropped.

verbose

Turn on verbose output and fit progress

random.seed

Seed for the random number generator (useful for reproducible output)

max.iter

Maximum number of iterations of the optimization algorithm.

seed.V

Matrix to warm-start the optimization algorithm. This is typically the output of coef(fit). Note that this function will silently drop seed.V if the dimensions don't match the provided data.

Value

A "gensvm" S3 object is returned for which the print, predict, coef, and plot methods are available. It has the following items:

call

The call that was used to construct the model.

p

The value of the lp norm in the loss function

lambda

The regularization parameter used in the model.

kappa

The hinge function parameter used.

epsilon

The stopping criterion used.

weights

The instance weights type used.

kernel

The kernel function used.

gamma

The value of the gamma parameter of the kernel, if applicable

coef

The value of the coef parameter of the kernel, if applicable

degree

The degree of the kernel, if applicable

kernel.eigen.cutoff

The cutoff value of the reduced eigendecomposition of the kernel matrix.

verbose

Whether or not the model was fitted with progress output

random.seed

The random seed used to seed the model.

max.iter

Maximum number of iterations of the algorithm.

n.objects

Number of objects in the dataset

n.features

Number of features in the dataset

n.classes

Number of classes in the dataset

classes

Array with the actual class labels

V

Coefficient matrix

n.iter

Number of iterations performed in training

n.support

Number of support vectors in the final model

training.time

Total training time

Note

This function returns partial results when the computation is interrupted by the user.

Author(s)

Gerrit J.J. van den Burg, Patrick J.F. Groenen
Maintainer: Gerrit J.J. van den Burg <gertjanvandenburg@gmail.com>

References

Van den Burg, G.J.J. and Groenen, P.J.F. (2016). GenSVM: A Generalized Multiclass Support Vector Machine, Journal of Machine Learning Research, 17(225):1–42. URL https://jmlr.org/papers/v17/14-526.html.

See Also

coef, print, predict, plot, gensvm.grid, gensvm-package

Examples

x <- iris[, -5]
y <- iris[, 5]

# fit using the default parameters and show progress
fit <- gensvm(x, y, verbose=TRUE)

# fit with some changed parameters
fit <- gensvm(x, y, lambda=1e-6)

# Early stopping defined through epsilon
fit <- gensvm(x, y, epsilon=1e-3)

# Early stopping defined through max.iter
fit <- gensvm(x, y, max.iter=1000)

# Nonlinear training
fit <- gensvm(x, y, kernel='rbf', max.iter=1000)
fit <- gensvm(x, y, kernel='poly', degree=2, gamma=1.0, max.iter=1000)

# Setting the random seed and comparing results
fit <- gensvm(x, y, random.seed=123, max.iter=1000)
fit2 <- gensvm(x, y, random.seed=123, max.iter=1000)
all.equal(coef(fit), coef(fit2))



gensvm documentation built on Feb. 16, 2023, 5:58 p.m.