Please use R-code for the following questions.
2.) Write a function ”neighbors(data, t, k)” that will return
the k closest neighbors of a vector t from a set of
vectors. Use the Euclidean distance function in question
1 to determine the distance of vector t and each vector in the data
set.
3.) Write a function ”KNN(train, t, k)” that returns
the predicted class of a vector t base on the training data. You
will call the neighbors() function to get the set of k nearest
neighbors. You will then predict the class of t as the majority
class of these neighbors.
n2 Σ(u, - υ)? 1=1
Please use R-code for the following questions. 2.) Write a function ”neighbors(data, t, k)” that will return the k close
-
- Site Admin
- Posts: 899559
- Joined: Mon Aug 02, 2021 8:13 am