Quadratic discrimination prediction
The function uses the output from the function qda
(Section A.3.2) and a -vector , and calculates the predicted group for this .
predict_qda(qd, newx)
qd
: The output from qda
.newx
: A -vector whose components match the variables used in the qda
function.A -vector of the discriminant values in (11.48) for the given .
# Load Iris Data data(iris) # Build data x.iris <- as.matrix(iris[, 1:4]) n <- nrow(x.iris) # Gets group vector (1, ... , 1, 2, ..., 2, 3, ... , 3) y.iris <- rep(1:3, c(50, 50, 50)) # Perform QDA qd.iris <- qda(x.iris, y.iris) yhat.qd <- NULL for (i in seq_len(n)) { yhat.qd <- c(yhat.qd, imax(predict_qda(qd.iris, x.iris[i, ]))) } table(yhat.qd, y.iris)
qda
, imax
Useful links