tropsvm | R Documentation |
Fit a discriminative two-class classifier via linear programming defined by the tropical hyperplane which maximizes the minimum tropical distance from data points to itself in order to separate the data points into sectors (half-spaces) in the tropical projective torus.
tropsvm(x, y, auto.assignment = FALSE, assignment = NULL, ind = 1)
x |
a data matrix, of dimension nobs x nvars; each row is an observation vector. |
y |
a response vector with one label for each row/component of x. |
auto.assignment |
a logical value indicating if to provide an |
assignment |
a numeric vector of length 4 indicating the sectors of tropical hyperplane that the
data will be assigned to. The first and third elements in the |
ind |
a numeric value or a numeric vector ranging from 1 to 70 indicating which classification method
to be used. There are 70 different classification methods. Details of a given method can be retrieved by |
An object with S3 class tropsvm
containing the fitted model, including:
apex |
The negative apex of the fitted optimal tropical hyperplane. |
assignment |
The user-input or auto-found |
index |
The user-input classification method. |
levels |
The name of each category, consistent with categories in |
predict
, coef
and the cv.tropsvm
function.
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.