qdap | R Documentation |
This function runs the Quadratic Discriminant Analysis by Projection (QDAP) method.
qdap(
x,
y,
xnew = NULL,
lambda = 0,
iter = 1,
method = "Penalization",
par = NULL,
max_iter = 1000,
optim = "codesc"
)
x |
A matrix containing the predictors of the training data. |
y |
A 0-1 vector containing the class labels of the training data. |
xnew |
A matrix containing the predictors of the test data. |
lambda |
The tuning parameter used for either the "Penalization" method or the "Thresholding" method. (Beta) |
iter |
Number of iterations to apply QDAP. If greater than 1, this will keep searching the optimal direction in the orthogonal complement of the previous optimal subspace. (Beta) |
method |
A method to get sparse optimal direction. "Penalization" for penalizing over the l2 norm of the optimal direction, or "Thresholding" for thresholding over each entry of the optimal direction. (Beta) |
par |
A vector representing the initial direction for the optimization subroutine. |
max_iter |
Maximum number of iterations for the optimization subroutine to run. |
optim |
The optimization method used towards the classification error function. "BFGS" for Broyden–Fletcher–Goldfarb–Shanno algorithm, or "codesc" for coordinate descent algorithm. |
This function only handles two-class classification problems. It tries to find the direction that minimizes the sample classification error under the heteroscedastic Gaussian assumption. It then projects the data onto the optimal direction, and performs 1-D regular QDA.
If not specified by the user, the initial direction for the optimization subroutine is either the LDA direction, or the direction that maximizes the ratio of two quadratic forms induced by the covariance matrices.
If the covariance matrices are singular, a tiny scalar matrix is added to them for numerical stability.
Multiple rounds of applications of QDAP is implemented (still in beta status). See the argument 'iter'.
Penalization/Thresholding is implemented to find sparse optimal direction (still in beta status). See the arguments 'lambda' and 'method'.
If 'xnew' is not supplied, the return value is a list containing 'qdap_rule', 'drt' and 'conv'. If 'xnew' is supplied, in addition to these, it also contains 'class':
class |
A 0-1 vector containing the predicted class label of the test data 'xnew'. |
qdap_rule |
The QDAP classification rule, a function that takes a vector of the same dimension as each training sample, and returns the predicted class label. |
drt |
a vector representing the optimal direction to project data onto. |
conv |
An integer code. ‘0’ indicates successful completion of the optimization method. |
Iris <- iris[-which(iris$Species == "virginica"), ] # use the first two species only
## Set up training and test data
set.seed(2021)
n <- nrow(Iris)
train <- sample(1:n, n/2)
x <- Iris[train, 1:4]
y <- as.integer(Iris[train, 5] == "setosa")
xnew <- Iris[-train, 1:4]
ynew <- as.integer(Iris[-train, 5] == "setosa")
## Calculate classification error
fit <- qdap(x, y, xnew)
sum(fit$class != ynew)/length(ynew)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.