svmr: SVM Regression or Discrimination

View source: R/svmr.R

svmrR Documentation

SVM Regression or Discrimination

Description

Function svmr and svmc are wrappers for fitting regression and discrimination SVM models, respectively, using function ksvm of package kernlab (thanks to Karatzoglou et al.) available on CRAN. This package uses the tool box LIVSIM (Chang & Lin, http://www.csie.ntu.edu.tw/~cjlin/libsvm).

The functions use parameterization 'C', not the 'nu' parameterization.

The syntax and outputs are the same as for the other kernel models in package rnirs.

See also the tuning facility with splitpar. Usual preliminary ranges are for instance:

- C <- 10^(-5:15)

- epsilon <- seq(.1, .3, by = .1)

- sigma <- 10^(-6:3)

Usage


svmr(Xr, Yr, Xu, Yu = NULL, C = 1, epsilon = .1, kern = krbf, 
                 print = TRUE, ...)

svmc(Xr, Yr, Xu, Yu = NULL, C = 1, epsilon = .1, kern = krbf, 
                 print = TRUE, ...)

Arguments

Xr

A n x p matrix or data frame of reference (= training) observations.

Yr

A vector of length n of reference (= training) responses.

Xu

A m x p matrix or data frame of new (= test) observations to predict.

Yu

A vector of length m of the true responses for Xu. Default to NULL.

C

A value, or vector of values, of the cost of constraints violation. This is the 'C'-constant of the regularization term in the Lagrange formulation

epsilon

A value, or vector of values, of epsilon in the insensitive-loss function.

kern

A function defining the considered kernel (Default to krbf). See krbf for syntax and other available kernel functions.

print

Logical (default = TRUE). If TRUE, fitting information are printed.

...

Optionnal arguments to pass in the kernel function defined in kern. The value set in the kernel parameters (e.g. sigma for krbf) can be a scalar or a vector of several values.

Value

A list of outputs (see examples), such as:

y

Responses for the test data.

fit

Predictions for the test data.

r

Residuals for the test data.

References

Karatzoglou, A. et al. 2019. Package kernlab: Kernel-Based Machine Learning Lab. Version 0.9-29 https://cran.r-project.org/

Chang C., Lin C.. LIBSVM: a library for Support Vector Machines http://www.csie.ntu.edu.tw/~cjlin/libsvm

Examples


data(datcass)
Xr <- datcass$Xr
yr <- datcass$yr
Xu <- datcass$Xu
yu <- datcass$yu
Xr <- detrend(Xr)
Xu <- detrend(Xu)
dim(Xr)
dim(Xu)

C <- 1e3
epsilon <- 0.1
sigma <- c(10, 100)
fm <- svmr(Xr, yr, Xu, yu, C = C, epsilon = epsilon, kern = krbf, sigma = sigma)
z <- mse(fm, ~ C + epsilon + sigma)
z[z$rmsep == min(z$rmsep), ][1, ]

data(datforages)
Xr <- datforages$Xr
yr <- datforages$yr
Xu <- datforages$Xu
yu <- datforages$yu
Xr <- savgol(snv(Xr), n = 21, p = 2, m = 2)
Xu <- savgol(snv(Xu), n = 21, p = 2, m = 2)
table(yr)
table(yu)

C <- 1e3
epsilon <- 0.1
sigma <- c(10, 100)
fm <- svmc(Xr, yr, Xu, yu, C = C, epsilon = epsilon, kern = krbf, sigma = sigma)
z <- err(fm, ~ C + epsilon + sigma)
z[z$errp == min(z$errp), ][1, ]


mlesnoff/rnirs documentation built on April 24, 2023, 4:17 a.m.