## Guttman intelligence data
Delta <- sim2diss(Guttman1965[[1]])
class <- Guttman1965[[2]]
## ordinal MDS fit
mds_gut <- mds(Delta, ndim = 2, type = "ordinal")
mds_gut
cols <- rainbow_hcl(4)[as.numeric(class)]
plot(mds_gut, col = cols, label.conf = list(col = cols))
legend("bottomright", legend = levels(class), cex = 0.7, col = rainbow_hcl(4), pch = 19)
## radial SVM fit
X <- mds_gut$conf ## extract configuration
dat <- data.frame(class = class, X) ## merge with class vector
costvec <- 2^seq(-4, 4) ## tuning parameter grid
gamma <- seq(0.01, 0.5, 10)
set.seed(111)
svm_gut <- tune.svm(class ~ D1 + D2, data = dat, kernel = "radial",
cross = 10, cost = costvec)$best.model
svm_gut
preds <- predict(svm_gut, data = dat) ## predicted classes
table(obs = class, pred = preds) ## confusion matrix
svm_mdsplot(mds_gut, svm_gut, dat$class, inset = c(-0.3, 0.5))
Run the code above in your browser using DataLab