Some of the exercises are not tested by Dodona (for example the plots), but it is still useful to try them.
train
that is TRUE for all the observation from 1990 to 2008. (1990 and 2008 included)test
that is TRUE for all the observation from 2009 to 2010. (2009 and 2010 included)Weekly.test
that only contains the test observations (dependent + independent variables).Direction.test
that only contains the test observations.
Lag2
as the only predictor. Store the model in glm.fit
.glm.table
and the accuracy in glm.acc
.
Repeat question 4 using LDA. Store the model in lda.fit
, the confusion matrix in lda.table
and the accuracy in lda.acc
.
Repeat question 4 using QDA. Store the model in qda.fit
, the confusion matrix in qda.table
and the accuracy in qda.acc
.
Repeat question 4 using Naïve Bayes. Store the model in nb.fit
, the confusion matrix in nb.table
and the accuracy in nb.acc
. (Use the naiveBayes()
function from the e1071
package.)
Repeat question 4 using KNN with \(K = 1\). Use a seed value of 1.
Store the model in knn.pred
, the confusion matrix in knn.table
and the accuracy in knn.acc
.
Recall that the KNN function
knn()
requires four inputs:
- A matrix containing the predictors associated with the training data, labeled
train.X
- A matrix containing the predictors associated with the data for which we wish to make predictions, labeled
test.X
.- A vector containing the class labels for the training observations, labeled
train.Direction
.- A value for \(K\), the number of nearest neighbors to be used by the classifier.
Inspect the results of the 4 models.
Assume that:
ISLR2
, MASS
, e1071
, and class
libraries have been loadedWeekly
dataset has been loaded and attached