class_docstr: Implementation of the permutation feature importance for tabular datasets. The method measure the importance
  of a feature as the relative increase/decrease in the loss/score function when the feature values are permuted.
  Supports black-box models.
  
  For details of the method see the papers:
  
   - https://link.springer.com/article/10.1023/A:1010933404324
  
   - https://arxiv.org/abs/1801.01489
docstr: Helper function to compute a metric. It also checks if the metric function contains in its signature the
  arguments `y_true`, `y_pred` or `y_score`, and optionally `sample_weight`.
  
  Parameters
  ----------
  metric_fn
      Metric function to be used. Note that the loss/score function must be compatible with the
      `y_true`, `y_pred`, and optionally with `sample_weight`.
  y, y_hat, sample_weight
      See :py:meth:`alibi.explainers.permutation_importance.PermutationImportance._compute_metrics`.
  
  Returns
  -------
  Evaluation of the metric.
docstr_tok: ["Helper","function","to","compute","a","metric",".","It","also","checks","if","the","metric","function","contains","in","its","signature","the","arguments","`","y_true","`",",","`","y_pred","`","or","`","y_score","`",",","and","optionally","`","sample_weight","`",".","Parameters","--","--","--","--","--","metric_fn","Metric","function","to","be","used",".","Note","that","the","loss\/score","function","must","be","compatible","with","the","`","y_true","`",",","`","y_pred","`",",","and","optionally","with","`","sample_weight","`",".","y",",","y_hat",",","sample_weight","See",":","py",":","meth",":","`","alibi.explainers.permutation_importance.PermutationImportance._compute_metrics","`",".","Returns","--","--","--","-","Evaluation","of","the","metric","."]
code: def _compute_metric(
      metric_fn: Callable[
          [np.ndarray, np.ndarray, Optional[np.ndarray]], float
      ],
      y: np.ndarray,
      y_hat: np.ndarray,
      sample_weight: Optional[np.ndarray] = None,
  ) -> float:
      """
      Helper function to compute a metric. It also checks if the metric function contains in its signature the
      arguments `y_true`, `y_pred` or `y_score`, and optionally `sample_weight`.
  
      Parameters
      ----------
      metric_fn
          Metric function to be used. Note that the loss/score function must be compatible with the
          `y_true`, `y_pred`, and optionally with `sample_weight`.
      y, y_hat, sample_weight
          See :py:meth:`alibi.explainers.permutation_importance.PermutationImportance._compute_metrics`.
  
      Returns
      -------
      Evaluation of the metric.
      """
      str_args = inspect.signature(metric_fn).parameters.keys()
  
      if "y_true" not in str_args:
          raise ValueError(
              "The `scoring` function must have the argument `y_true` in its definition."
          )
  
      if ("y_pred" not in str_args) and ("y_score" not in str_args):
          raise ValueError(
              "The `scoring` function must have the argument `y_pred` or `y_score` in its definition."
          )
  
      kwargs: Dict[str, Optional[np.ndarray]] = {
          "y_true": y,
          "y_pred" if "y_pred" in str_args else "y_score": y_hat,
      }
  
      if "sample_weight" not in str_args:
          # some metrics might not support `sample_weight` such as:
          # https://scikit-learn.org/stable/modules/generated/sklearn.metrics.max_error.html#sklearn.metrics.max_error
          if sample_weight is not None:
              logger.warning(
                  f"The loss function '{metric_fn.__name__}' does not support argument `sample_weight`. "
                  f"Calling the method without `sample_weight`."
              )
  
      else:
          # include `sample_weight` int the `kwargs` if the metric supports it
          kwargs["sample_weight"] = sample_weight
  
      return metric_fn(**kwargs)
  
imports: import copy
  import inspect
  import logging
  import math
  import numbers
  import sys
  from collections import defaultdict
  from copy import deepcopy
  from enum import Enum
  from typing import Any, Callable, Dict, List, Optional, Tuple, Union, no_type_check
  import matplotlib.pyplot
  import numpy
  import sklearn.metrics
  from tqdm import tqdm
  from alibi.api.defaults import DEFAULT_DATA_PERMUTATION_IMPORTANCE, DEFAULT_META_PERMUTATION_IMPORTANCE
  from alibi.api.interfaces import Explainer, Explanation
label_desc: Use image node_id 5 for calling the PermutationImportance obj's underlying member method code with example usage: obj._compute_metric(metric_fn, y, y_hat, sample_weight) and returns: metric_fn