Question: 3 . Implement K - Nearest Neighborhood with R / Python ( a ) Given a dataset Xn times p ( n observations, p

3. Implement K-Nearest Neighborhood with R/Python
(a) Given a dataset Xn\times p (n observations, p features), Yn\times 1(class labels, yi =0,1), write
a function to classify one new point xnew (i.e. to predict ynew).(Please do NOT use
any packages in R/Python, write your own code.)
Hint:
2
i. Find all the distances between xnew and Xn\times p
ii. Pick up class labels of the nearest K points
iii. Predict ynew by majority vote
(b) Run your function using dataset HW1Q3data.Rdata in R or HW1Q3data.npy
in Python (use data=numpy.load(HW1Q3data.npy,allow
pickle=True).item()
after installing package numpy to load the data , which will return a dict object)
to classify xnew, with K =5.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!