#NEWLINE# def thresholdBlocks( self , blocks , recall_weight = 1.5 ) : #NEWLINE# #INDENT# '\n        Returns the threshold that maximizes the expected F score, a\n        weighted average of precision and recall for a sample of\n        blocked data.\n\n        Arguments:\n\n        blocks -- Sequence of tuples of records, where each tuple is a\n                  set of records covered by a blocking predicate\n\n        recall_weight -- Sets the tradeoff between precision and\n                         recall. I.e. if you care twice as much about\n                         recall as you do precision, set recall_weight\n                         to 2.\n\n        ' #NEWLINE# probability = core . scoreDuplicates ( self . _blockedPairs ( blocks ) , self . data_model , self . classifier , self . num_cores ) [ 'score' ] #NEWLINE# probability . sort ( ) #NEWLINE# probability = probability [ : : ( - 1 ) ] #NEWLINE# expected_dupes = numpy . cumsum ( probability ) #NEWLINE# recall = ( expected_dupes / expected_dupes [ ( - 1 ) ] ) #NEWLINE# precision = ( expected_dupes / numpy . arange ( 1 , ( len ( expected_dupes ) + 1 ) ) ) #NEWLINE# score = ( ( recall * precision ) / ( recall + ( ( recall_weight ** 2 ) * precision ) ) ) #NEWLINE# i = numpy . argmax ( score ) #NEWLINE# logger . info ( 'Maximum expected recall and precision' ) #NEWLINE# logger . info ( 'recall: %2.3f' , recall [ i ] ) #NEWLINE# logger . info ( 'precision: %2.3f' , precision [ i ] ) #NEWLINE# logger . info ( 'With threshold: %2.3f' , probability [ i ] ) #NEWLINE# return expected_dupes [ i ]