예제 #1
0
def cluster_distance(cluster1, cluster2, distance_agg=min):
    """compute all the pairwise distances between cluster1 and cluster2
    and apply distance_agg to the resulting list"""
    return distance_agg([
        algebra.distance(input1, input2) for input1 in get_values(cluster1)
        for input2 in get_values(cluster2)
    ])
예제 #2
0
파일: knn.py 프로젝트: mjamesruggiero/tripp
def knn_classify(k, labeled_points, new_point):
    """each labeled point should be a pair (point, label)"""
    by_distance = sorted(labeled_points, key=lambda (point, _): algebra.distance(point, new_point))

    k_nearest_labels = [label for _, label in by_distance[:k]]

    return majority_vote(k_nearest_labels)
예제 #3
0
def knn_classify(k, labeled_points, new_point):
    """each labeled point should be a pair (point, label)"""
    by_distance = sorted(labeled_points,
                         key=lambda
                         (point, _): algebra.distance(point, new_point))

    k_nearest_labels = [label for _, label in by_distance[:k]]

    return majority_vote(k_nearest_labels)
예제 #4
0
def cluster_distance(cluster1, cluster2, distance_agg=min):
    """compute all the pairwise distances between cluster1 and cluster2
    and apply distance_agg to the resulting list"""
    return distance_agg([algebra.distance(input1, input2)
                         for input1 in get_values(cluster1)
                         for input2 in get_values(cluster2)])