#NEWLINE# @ ignore_warnings #NEWLINE# def _check_averaging( metric , y_true , y_pred , y_true_binarize , y_pred_binarize , is_multilabel ) : #NEWLINE# #INDENT# ( n_samples , n_classes ) = y_true_binarize . shape #NEWLINE# label_measure = metric ( y_true , y_pred , average = None ) #NEWLINE# assert_array_almost_equal ( label_measure , [ metric ( y_true_binarize [ : , i ] , y_pred_binarize [ : , i ] ) for i in range ( n_classes ) ] ) #NEWLINE# micro_measure = metric ( y_true , y_pred , average = 'micro' ) #NEWLINE# assert_almost_equal ( micro_measure , metric ( y_true_binarize . ravel ( ) , y_pred_binarize . ravel ( ) ) ) #NEWLINE# macro_measure = metric ( y_true , y_pred , average = 'macro' ) #NEWLINE# assert_almost_equal ( macro_measure , np . mean ( label_measure ) ) #NEWLINE# weights = np . sum ( y_true_binarize , axis = 0 , dtype = int ) #NEWLINE# if ( np . sum ( weights ) != 0 ) : #NEWLINE# #INDENT# weighted_measure = metric ( y_true , y_pred , average = 'weighted' ) #NEWLINE# assert_almost_equal ( weighted_measure , np . average ( label_measure , weights = weights ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# weighted_measure = metric ( y_true , y_pred , average = 'weighted' ) #NEWLINE# assert_almost_equal ( weighted_measure , 0 ) #NEWLINE# #UNINDENT# if is_multilabel : #NEWLINE# #INDENT# sample_measure = metric ( y_true , y_pred , average = 'samples' ) #NEWLINE# assert_almost_equal ( sample_measure , np . mean ( [ metric ( y_true_binarize [ i ] , y_pred_binarize [ i ] ) for i in range ( n_samples ) ] ) ) #NEWLINE# #UNINDENT# assert_raises ( ValueError , metric , y_true , y_pred , average = 'unknown' ) #NEWLINE# assert_raises ( ValueError , metric , y_true , y_pred , average = 'garbage' )