Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Implement a KNN (k nearest neighbors) classifier from scratch without using the scikitlearn library. This means, do not use the following import line in your

Implement a KNN (k nearest neighbors) classifier from scratch without using the scikitlearn library. This means, do not use the following import line in your submitted solution: from sklearn.neighbors import KNeighborsClassifier

Implement a function called knn(), which accepts three input parameters: a single observation, a reference dataset containing more than one observations, and k parameter defining how many nearest neighbors should vote on the classification: knn(newObservation, referenceData, k=3)

The reference observation data should be a pandas dataframe, with rows as observations and columns as input variables. The last column of this dataframe should be the output/class variable. The parameter k should default to 3 (voting is based on 3 nearest neighbors). Your knn() function should not assume any dimensionality of the data and should be able to perform classification on any dimensionality of the data as long as the newObservation and the referenceData are of the same dimensions. The newObservation variable refers to a new observation for which we want to predict a class label.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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_2

Step: 3

blur-text-image_3

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

Data Management Databases And Organizations

Authors: Richard T. Watson

2nd Edition

0471180742, 978-0471180746

More Books

Students also viewed these Databases questions