Answered step by step
Verified Expert Solution
Link Copied!

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)

image text in transcribed

> 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

This image shows an R script related to using the kNearest Neighbors kNN classification Heres a stepbystep breakdown of the code Steps and explanation ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Probability and Random Processes With Applications to Signal Processing and Communications

Authors: Scott Miller, Donald Childers

2nd edition

123869811, 978-0121726515, 121726517, 978-0130200716, 978-0123869814

More Books

Students also viewed these Mathematics questions