The predict() function returns a list with three elements.
The first element, class, contains LDA’s predictions about the movement of the market.
The second element, posterior, is a matrix whose kth column contains the
posterior probability that the corresponding observation belongs to the kth
class, computed from (4.10). Finally, x contains the linear discriminants,
described earlier.
> lda.pred <- predict(lda.fit, Smarket.2005)
> names(lda.pred)
[1] "class" "posterior" "x"
The LDA and logistic regression predictions are almost identical.
> lda.class <- lda.pred$class
> table(lda.class, Direction.2005)
Direction.2005
lda.class Down Up
Down 35 35
Up 76 106
> mean(lda.class == Direction.2005)
[1] 0.5595238
Try creating a confusion matrix and calculating the accuracy of the following model (store the table and accuracy in lda.table3 and lda.acc3 respectively):
Assume that:
ISLR2 and MASS libraries have been loadedSmarket dataset has been loaded and attached