def hamming_loss(y_true, y_pred, labels=None, sample_weight=None, classes=None):
 if (classes is not None):
  warnings.warn("'classes' was renamed to 'labels' in version 0.18 and will be removed in 0.20.", DeprecationWarning)
  labels = classes
 (y_type, y_true, y_pred) = _check_targets(y_true, y_pred)
 if (labels is None):
  labels = unique_labels(y_true, y_pred)
 else:
  labels = np.asarray(labels)
 if (sample_weight is None):
  weight_average = 1.0
 else:
  weight_average = np.mean(sample_weight)
 if y_type.startswith('multilabel'):
  n_differences = count_nonzero((y_true - y_pred), sample_weight=sample_weight)
  return (n_differences / ((y_true.shape[0] * len(labels)) * weight_average))
 elif (y_type in ['binary', 'multiclass']):
  return _weighted_sum((y_true != y_pred), sample_weight, normalize=True)
 else:
  raise ValueError('{0} is not supported'.format(y_type))

def hamming_loss ( y_true , y_pred , labels = None , sample_weight = None , classes = None ) : if ( classes is not None ) : warnings . warn ( "'classes' was renamed to 'labels' in version 0.18 and will be removed in 0.20." , DeprecationWarning ) labels = classes ( y_type , y_true , y_pred ) = _check_targets ( y_true , y_pred ) if ( labels is None ) : labels = unique_labels ( y_true , y_pred ) else : labels = np . asarray ( labels ) if ( sample_weight is None ) : weight_average = 1.0 else : weight_average = np . mean ( sample_weight ) if y_type . startswith ( 'multilabel' ) : n_differences = count_nonzero ( ( y_true - y_pred ) , sample_weight = sample_weight ) return ( n_differences / ( ( y_true . shape [ 0 ] * len ( labels ) ) * weight_average ) ) elif ( y_type in [ 'binary' , 'multiclass' ] ) : return _weighted_sum ( ( y_true != y_pred ) , sample_weight , normalize = True ) else : raise ValueError ( '{0} is not supported' . format ( y_type ) )
compute the average hamming loss .