Description Usage Arguments Value See Also Examples
View source: R/predict.tropsvm.R
Predicts values based upon a model trained by tropsvm
.
1 2 |
object |
a fitted |
newx |
a data matrix, of dimension nobs x nvars used as testing data. |
... |
Not used. Other arguments to predict. |
A vector of predicted values of a vector of labels.
summary
, coef
and the tropsvm
function.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | # data generation
library(Rfast)
e <- 100
n <- 10
N <- 10
s <- 5
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)
# test with new data
pred <- predict(tropsvm_fit, newx)
# check with accuracy
table(pred, newy)
# compute testing accuracy
sum(pred == newy) / length(newy)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.