def form_clusters(instances, assignments): print "Forming Clusters" cluster_map = dict() class Mock: pass for x in xrange(_number_of_clusters): m = Mock() m.label = None cluster_map[x] = cluster.Cluster(list(), m, x) for instance, assignment in zip(instances, assignments): m = Mock() m._id = instance[0] m.label = instance[1] cluster_map[assignment].members.append(m) clusters = cluster_map.values() map(lambda cluster: cluster.set_label(), clusters) print "Done\n" return clusters
def form_clusters(true_labels, predicted_labels): cluster_map = dict() class Mock: pass for x in xrange(predicted_labels.max() + 1): m = Mock() m.label = None cluster_map[x] = cluster.Cluster(list(), m, x) count = 0 for true, predicted in zip(true_labels, predicted_labels): m = Mock() m._id = count count += 1 m.label = true cluster_map[predicted].members.append(m) clusters = filter(lambda cluster: cluster.members, cluster_map.values()) map(lambda cluster: cluster.set_label(), clusters) return clusters
def form_clusters(true_labels, predicted_labels): cluster_map = dict() class Mock: pass for x in xrange(predicted_labels.max() + 1): m = Mock() m.label = None cluster_map[x] = cluster.Cluster(list(), m, x) count = 0 for true, predicted in zip(true_labels, predicted_labels): m = Mock() m._id = count count += 1 m.label = true cluster_map[predicted].members.append(m) clusters = filter(lambda cluster: cluster.members, cluster_map.values()) map(lambda cluster: cluster.set_label(), clusters) return clusters