#NEWLINE# def test_compute_cut( ) : #NEWLINE# #INDENT# random = RandomState ( ) #NEWLINE# predictions = random . permutation ( 100 ) #NEWLINE# labels = numpy . ones ( 100 ) #NEWLINE# for eff in [ 0.1 , 0.5 , 0.75 , 0.99 ] : #NEWLINE# #INDENT# cut = compute_cut_for_efficiency ( eff , labels , predictions ) #NEWLINE# assert ( ( numpy . sum ( ( predictions > cut ) ) / len ( predictions ) ) == eff ) , 'the cut was set wrongly' #NEWLINE# #UNINDENT# weights = numpy . array ( random . exponential ( size = 100 ) ) #NEWLINE# for eff in random . uniform ( size = 100 ) : #NEWLINE# #INDENT# cut = compute_cut_for_efficiency ( eff , labels , predictions , sample_weight = weights ) #NEWLINE# lower = ( numpy . sum ( weights [ ( predictions > ( cut + 1 ) ) ] ) / numpy . sum ( weights ) ) #NEWLINE# upper = ( numpy . sum ( weights [ ( predictions > ( cut - 1 ) ) ] ) / numpy . sum ( weights ) ) #NEWLINE# assert ( lower < eff < upper )