code: def hamming_loss(
      y_true, y_pred, labels=None, sample_weight=None, classes=None
  ):
      """Compute the average Hamming loss.
  
      The Hamming loss is the fraction of labels that are incorrectly predicted.
  
      Read more in the :ref:`User Guide <hamming_loss>`.
  
      Parameters
      ----------
      y_true : 1d array-like, or label indicator array / sparse matrix
          Ground truth (correct) labels.
  
      y_pred : 1d array-like, or label indicator array / sparse matrix
          Predicted labels, as returned by a classifier.
  
      labels : array, shape = [n_labels], optional (default=None)
          Integer array of labels. If not provided, labels will be inferred
          from y_true and y_pred.
  
          .. versionadded:: 0.18
  
      sample_weight : array-like of shape = [n_samples], optional
          Sample weights.
  
          .. versionadded:: 0.18
  
      classes : array, shape = [n_labels], optional
          (deprecated) Integer array of labels. This parameter has been
           renamed to ``labels`` in version 0.18 and will be removed in 0.20.
  
      Returns
      -------
      loss : float or int,
          Return the average Hamming loss between element of ``y_true`` and
          ``y_pred``.
  
      See Also
      --------
      accuracy_score, jaccard_similarity_score, zero_one_loss
  
      Notes
      -----
      In multiclass classification, the Hamming loss correspond to the Hamming
      distance between ``y_true`` and ``y_pred`` which is equivalent to the
      subset ``zero_one_loss`` function.
  
      In multilabel classification, the Hamming loss is different from the
      subset zero-one loss. The zero-one loss considers the entire set of labels
      for a given sample incorrect if it does entirely match the true set of
      labels. Hamming loss is more forgiving in that it penalizes the individual
      labels.
  
      The Hamming loss is upperbounded by the subset zero-one loss. When
      normalized over samples, the Hamming loss is always between 0 and 1.
  
      References
      ----------
      .. [1] Grigorios Tsoumakas, Ioannis Katakis. Multi-Label Classification:
             An Overview. International Journal of Data Warehousing & Mining,
             3(3), 1-13, July-September 2007.
  
      .. [2] `Wikipedia entry on the Hamming distance
             <https://en.wikipedia.org/wiki/Hamming_distance>`_
  
      Examples
      --------
      >>> from sklearn.metrics import hamming_loss
      >>> y_pred = [1, 2, 3, 4]
      >>> y_true = [2, 2, 3, 4]
      >>> hamming_loss(y_true, y_pred)
      0.25
  
      In the multilabel case with binary label indicators:
  
      >>> hamming_loss(np.array([[0, 1], [1, 1]]), np.zeros((2, 2)))
      0.75
      """
      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))
  
imports: from __future__ import division
  import warnings
  import numpy
  from scipy.sparse import coo_matrix
  from scipy.sparse import csr_matrix
  from ..preprocessing import LabelBinarizer, label_binarize
  from ..preprocessing import LabelEncoder
  from ..utils import assert_all_finite
  from ..utils import check_array
  from ..utils import check_consistent_length
  from ..utils import column_or_1d
  from ..utils.multiclass import unique_labels
  from ..utils.multiclass import type_of_target
  from ..utils.validation import _num_samples
  from ..utils.sparsefuncs import count_nonzero
  from ..utils.fixes import bincount
  from ..exceptions import UndefinedMetricWarning
label_desc: Use image node_id 16 for calling a global function with example usage: hamming_loss(y_true, y_pred, labels, sample_weight, classes) and returns: unknown, _weighted_sum