The task is to generalise the 1-Nearest-Neighbours code provided
in the lab workbooks into
a K-Nearest-Neighbours classifier. You should submit a file of
python code that implements
a python class called simple_KNN.
This class should support these attributes: modelX, modelY,
labelsPresent and the following
methods:
__init__(self,K, verbose=False) where
=> the parameter K specifies the number of neighbours to be
considered when
making a prediction, and verbose controls whether debugging
fit(self,X,y) where:
=> X is a 2-dimensional numpy arrays with a column for each
feature and a row
for each different data item and y is a one-dimensional numpy array
of labels
encoded as integers, with one entry for each different data
item.
predict(self,newItems), where
=> newItems is a two-dimensional numpy array with the same
number of
columns as the training data X.
You may choose to implement the following methods to help you
manage your code
complexity:
predict_new_item(self,newItem)
get_ids_of_k_closest(distFromNewItem, K)
euclidean_distance(a,b ) (using the code from the file
week7_utilstils.py)
To demonstrate your understanding of how the algorithm works, your
code should be fully
commented with your own comments, you may only import the python
libraries math and
numpy (imported as np).
The task is to generalise the 1-Nearest-Neighbours code provided in the lab workbooks into a K-Nearest-Neighbours classi
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
The task is to generalise the 1-Nearest-Neighbours code provided in the lab workbooks into a K-Nearest-Neighbours classi
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!