Question: > library(class) A > train.x-cbind(Lag1,Lag2) [train,] > test.x-cbind(Lag1,Lag2) [!train,] > train. > Direction-Direction[train] > set.seed(1) > knn. pred knn(train. x, test.x, train. Direction, k=1)
![> library(class) A > train.x-cbind(Lag1,Lag2) [train,] > test.x-cbind(Lag1,Lag2) [!train,] > train. >](https://s3.amazonaws.com/si.experts.images/answers/2024/05/66447a4e4f6bd_79066447a4e3f281.jpg)
> library(class) A > train.x-cbind(Lag1,Lag2) [train,] > test.x-cbind(Lag1,Lag2) [!train,] > train. > Direction-Direction[train] > set.seed(1) > knn. pred knn(train. x, test.x, train. Direction, k=1) > table (knn. pred, Direction. 2005) Direction. 2005 knn. pred Down up Down 72 73 Up 69 99 >(72-99)/(72-73+69+99) [1] 0.5463259 >knn. pred-knn(train.x,test.x, train. Direction, k=3) > table (knn. pred, Direction. 2005) Direction. 2005 knn. pred Down up Down 79 70 up 62 102 > mean (knn. pred--Direction. 2005) [1] 0.5782748
Step by Step Solution
There are 3 Steps involved in it
This image shows an R script related to using the kNearest Neighbors kNN classification Heres a stepbystep breakdown of the code Steps and explanation ... View full answer
Get step-by-step solutions from verified subject matter experts
