def batch_compute_similarities(self, distance_metric='jaccard', threshold = 0.5):

        # Add instances to the min_hash class
        self.vprint('Adding %d samples to minhash...' % (len(self._records)))
        if self._record_type == 'list':
            for uuid, record in enumerate(self._records):
                self._min_hash.add_instance(uuid, record)
        else:
            for uuid in xrange(self._records.shape[0]):
                self._min_hash.add_instance(uuid, self._get_row(uuid))

        # Build up the min hash signatures
        self.vprint('Computing All Candidate Matches...')
        self._min_hash.compute_all_candidate_matches()

        # Get Candidate Pairs
        candidates = self._min_hash.get_candidate_pairs()

        # Output some stats
        n_pairs = len(candidates)
        total_pairs = len(self._records)*len(self._records)
        self.vprint ('%d (%.2f%% out of %d) pairs returned from MinHash' % \
              (n_pairs, n_pairs*100.0/total_pairs, total_pairs))

        # Now process all the candidates events pairs and explicity
        # compute similarities based on the specified distance metric
        matches = []
        for source, target in candidates:

            # Make sure the source and target aren't the same
            if (source == target):
                continue

            # Compute Levenshtein Similarity between source and target
            if (distance_metric == 'levenshtein'):
                sim = self.l_sim(self._get_row(source), self._get_row(target))
                if (sim > threshold):
                    if (source < target):
                        matches.append((sim, source, target))
                    else:
                        matches.append((sim, target, source))

            # Compute Levenshtein Distance between source and target
            elif (distance_metric == 'levenshtein_D'):
                distance = self.levenshtein(self._get_row(source), self._get_row(target))
                if (distance < threshold):
                    if (source < target):
                        matches.append((distance, source, target))
                    else:
                        matches.append((distance, target, source))

            # Compute Levenshtein Distance between source and target
            elif (distance_metric == 'levenshtein_tapered'):
                distance = self.levenshtein_tapered(self._get_row(source), self._get_row(target))
                if (distance < threshold):
                    if (source < target):
                        matches.append((distance, source, target))
                    else:
                        matches.append((distance, target, source))

            # Compute Levenshtein Similarity between source and target
            elif (distance_metric == 'l_tapered_sim'):
                sim = self.l_tapered_sim(self._get_row(source), self._get_row(target))
                if (sim > threshold):
                    if (source < target):
                        matches.append((sim, source, target))
                    else:
                        matches.append((sim, target, source))

            # Compute a Jaccard Distance
            elif (distance_metric == 'jaccard'):
                sim = self.jaccard_sim(self._get_row(source), self._get_row(target))
                if (sim > threshold):
                    if (source < target):
                        matches.append((sim, source, target))
                    else:
                        matches.append((sim, target, source))

            # Catch unknown distance metric
            else:
                print 'Unknown distance metric', distance_metric
                raise NotImplementedError

        self.vprint('LSH: %s matches out of %s candidates (adjust parameters if needed)' % (len(matches), len(candidates)))

        # Return the matches list
        return matches
Use Banded LSH to reduce pairwise similarity calcs.
dataset/ETHPy150Open ClickSecurity/data_hacking/data_hacking/lsh_sims/lsh_sims.py/LSHSimilarities.batch_compute_similarities