def test_uniform_weight_with_0(self): """Test to see that _distance_weights return a weight of 1/d for each distance""" knn = Knn(n_neighbors=3) distances = np.array([0, .3, 4]) weights = knn._distance_weights(distances) assert np.allclose(weights, np.array([[1, 0], [1 / .3, .3], [ 1 / 4, 4 ]])), "distance_weights are not correct when we have distances of 0"
def test_distance_weight(self): """Test to see that _distance_weights return a weight of 1/d for each distance""" knn = Knn(n_neighbors=3) distances = np.array([2, .3, 4]) weights = knn._distance_weights(distances) assert np.allclose(weights, np.array([[1 / 2, 2], [1 / .3, .3], [1 / 4, 4]])), "distance_weights are not correct"