code: def getResponse(neighbors, weights=None):
    
    neighborResponse = []
    for x in range(len(neighbors)):
      neighborResponse.append(neighbors[x][-1])
  
    neighborResponse = np.array(neighborResponse).astype('float')
    if weights is None:
      weightedAvg = np.mean(neighborResponse)
    else:
      weightedAvg = np.sum(weights * neighborResponse)
  
    return weightedAvg
docs: Calculated weighted response based on a list of nearest neighbors
    :param neighbors: a list of neighbors, each entry is a data instance
    :param weights: a numpy array of the same length as the neighbors
    :return: weightedAvg: weighted average response