def _score(estimator, X_test, y_test, scorer):
 if (y_test is None):
  score = scorer(estimator, X_test)
 else:
  score = scorer(estimator, X_test, y_test)
 if hasattr(score, 'item'):
  try:
   score = score.item()
  except ValueError:
   pass
 if (not isinstance(score, numbers.Number)):
  raise ValueError(('scoring must return a number, got %s (%s) instead.' % (str(score), type(score))))
 return score

def _score ( estimator , X_test , y_test , scorer ) : if ( y_test is None ) : score = scorer ( estimator , X_test ) else : score = scorer ( estimator , X_test , y_test ) if hasattr ( score , 'item' ) : try : score = score . item ( ) except ValueError : pass if ( not isinstance ( score , numbers . Number ) ) : raise ValueError ( ( 'scoring must return a number, got %s (%s) instead.' % ( str ( score ) , type ( score ) ) ) ) return score
compute the score of an estimator on a given test set .