makeKernel: Compute kernel matrix

Description Usage Arguments Value Author(s) References See Also Examples

View source: R/VCR_auxiliaryFunctions.R

Description

Computes kernel value or kernel matrix, where the kernel type is extracted from an svm trained by e1071::svm.

Usage

1
makeKernel(X1, X2 = NULL, svfit)

Arguments

X1

first matrix (or vector) of coordinates.

X2

if not NULL, second data matrix or vector. If NULL, X2 is assumed equal to X1.

svfit

output from e1071::svm

.

Value

the kernel matrix, of dimensions nrow(X1) by nrow(X2). When both X1 and X2 are vectors, the result is a single number.

Author(s)

Raymaekers J., Rousseeuw P.J.

References

Raymaekers J., Rousseeuw P.J., Hubert M. (2021). Class maps for visualizing classification results. Technometrics, appeared online. doi: 10.1080/00401706.2021.1927849(link to open access pdf)

See Also

makeFV

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
library(e1071)
set.seed(1); X <- matrix(rnorm(200 * 2), ncol = 2)
X[1:100, ] <- X[1:100, ] + 2
X[101:150, ] <- X[101:150, ] - 2
y <- as.factor(c(rep("blue", 150), rep("red", 50))) # two classes
# We now fit an SVM with radial basis kernel to the data:
set.seed(1) # to make the result of svm() reproducible.
svmfit <- svm(y~.,  data = data.frame(X = X, y = y),  scale = FALSE,
             kernel = "radial", cost = 10, gamma = 1, probability = TRUE)
Kxx <- makeKernel(X, svfit = svmfit)
# The result is a square kernel matrix:
dim(Kxx) # 200 200
Kxx[1:5, 1:5]

# For more examples, we refer to the vignette:
## Not run: 
vignette("Support_vector_machine_examples")

## End(Not run)

classmap documentation built on Jan. 10, 2022, 1:06 a.m.