# NOT RUN {
# data generation
library(Rfast)
e <- 100
n <- 10
N <- 100
s <- 10
x <- rbind(
rmvnorm(n, mu = c(5, -5, rep(0, e - 2)), sigma = diag(s, e)),
rmvnorm(n, mu = c(-5, 5, rep(0, e - 2)), sigma = diag(s, e))
)
y <- as.factor(c(rep(1, n), rep(2, n)))
newx <- rbind(
rmvnorm(N, mu = c(5, -5, rep(0, e - 2)), sigma = diag(s, e)),
rmvnorm(N, mu = c(-5, 5, rep(0, e - 2)), sigma = diag(s, e))
)
newy <- as.factor(rep(c(1, 2), each = N))
# train the tropical svm
tropsvm_fit <- tropsvm(x, y, auto.assignment = TRUE, ind = 1)
coef(tropsvm_fit)
# test with new data
pred <- predict(tropsvm_fit, newx)
# check with accuracy
table(pred, newy)
# compute testing accuracy
sum(pred == newy) / length(newy)
# }
Run the code above in your browser using DataLab