fit method
Lesson 7 of 19 in Coddy's Introduction to Machine Learning course.
The KNN doesn’t have an explicit training phase. It simply stores the dataset. Only during the predict phase it calculates the distance between the new point to the rest.
Challenge
MediumImplement the Euclidean distance calculation in the distance method, and modify the fit method to store the list of points in self.points and the corresponding labels in self.labels. X_train are the points and y_train are the labels.
Try it yourself
import numpy
class KNN:
def __init__(self, k):
self.points = None
self.labels = None
self.k = k
def distance(self, point_a, point_b):
# Write your code here
def fit(self, X_train, y_train):
# Write your code here
pass
def predict(self, X_test):
pass