The package abclass provides implementations of the multi-category angle-based classifiers (Zhang & Liu, 2014) with the large-margin unified machines (Liu, et al., 2011) for high-dimensional data.
Note
This package is still very experimental and under active development. The function interface is subject to change without guarantee of backward compatibility.
One can install the released version from CRAN.
install.packages("abclass")
Alternatively, the version under development can be installed as follows:
if (! require(remotes)) install.packages("remotes")
::install_github("wenjie2wang/abclass", upgrade = "never") remotes
A toy example is as follows:
library(abclass)
packageVersion("abclass")
## [1] '0.5.0'
## toy examples for demonstration purpose
## reference: example 1 in Zhang and Liu (2014)
<- 400 # size of training set
ntrain <- 10000 # size of testing set
ntest <- 5 # number of actual predictors
p0 <- 45 # number of random predictors
p1 <- 5 # number of categories
k
set.seed(1)
<- ntrain + ntest; p <- p0 + p1
n <- seq_len(ntrain)
train_idx <- sample(k, size = n, replace = TRUE) # response
y <- matrix(rnorm(p0 * k), nrow = k, ncol = p0) # mean vector
mu ## normalize the mean vector so that they are distributed on the unit circle
<- mu / apply(mu, 1, function(a) sqrt(sum(a ^ 2)))
mu <- t(sapply(y, function(i) rnorm(p0, mean = mu[i, ], sd = 0.25)))
x0 <- matrix(rnorm(p1 * n, sd = 0.3), nrow = n, ncol = p1)
x1 <- cbind(x0, x1)
x <- x[train_idx, ]
train_x <- x[- train_idx, ]
test_x <- factor(paste0("label_", y))
y <- y[train_idx]
train_y <- y[- train_idx]
test_y
### logistic deviance loss with elastic-net penalty
<- cv.abclass(train_x, train_y, nlambda = 100, nfolds = 5,
model1 loss = "logistic", penalty = "lasso", alpha = 0.9)
<- predict(model1, test_x)
pred1 table(test_y, pred1)
## pred1
## test_y label_1 label_2 label_3 label_4 label_5
## label_1 1704 0 3 296 0
## label_2 0 1862 0 0 106
## label_3 4 11 1739 0 198
## label_4 3 12 0 1947 70
## label_5 0 63 30 1 1951
mean(test_y == pred1) # accuracy
## [1] 0.9203
### with groupwise lasso
<- cv.abclass(train_x, train_y, nlambda = 100, nfolds = 5,
model2 loss = "logistic", penalty = "glasso")
<- predict(model2, test_x)
pred2 table(test_y, pred2)
## pred2
## test_y label_1 label_2 label_3 label_4 label_5
## label_1 1994 1 2 3 3
## label_2 0 1784 0 0 184
## label_3 4 2 1336 0 610
## label_4 12 27 0 1963 30
## label_5 0 10 2 0 2033
mean(test_y == pred2) # accuracy
## [1] 0.911
## tuning by ET-Lasso instead of cross-validation
<- et.abclass(train_x, train_y, nlambda = 100,
model3 loss = "logistic", penalty = "glasso")
<- predict(model3, test_x)
pred3 table(test_y, pred3)
## pred3
## test_y label_1 label_2 label_3 label_4 label_5
## label_1 1991 1 5 5 1
## label_2 0 1842 0 0 126
## label_3 3 7 1643 0 299
## label_4 7 13 0 1997 15
## label_5 0 18 11 0 2016
mean(test_y == pred3) # accuracy
## [1] 0.9489
GNU General Public License (≥ 3)
Copyright holder: Eli Lilly and Company