Answered step by step
Verified Expert Solution
Question
1 Approved Answer
> 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. > 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started