def get_y(self, point): """ Use KNN algorithm to find the y value of the point. Parameters ---------- point: array Returns ---------- y: float """ heap = MaxHeap(self.k) for i in range(len(self.x)): distance = Learner.euclidean_distance(self.x[i], point) heap.add((distance, i, self.x[i], self.y[i])) # if the first value in the tuple is equal, heapq use the second value to compare values = heap.heapsort() values = [val[3] for val in values] return np.array(values).sum()/len(values)