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: Initialize the permutation feature importance.
  
  Parameters
  ----------
  predictor
      A prediction function which receives as input a `numpy` array of size `N x F`, and outputs a
      `numpy` array of size `N` (i.e. `(N, )`) or `N x T`, where `N` is the number of input instances,
      `F` is the number of features, and `T` is the number of targets. Note that the output shape must be
      compatible with the loss and score functions provided in `loss_fns` and `score_fns`.
  loss_fns
      A literal, or a list of literals, or a loss function, or a dictionary of loss functions having as keys the
      names of the loss functions and as values the loss functions (i.e., lower values are better). The available
      literal values are described in :py:data:`alibi.explainers.permutation_importance.LOSS_FNS`. Note that the
      `predictor` output must be compatible with every loss function. Every loss function is expected to receive
      the following arguments:
  
       - `y_true` : ``np.ndarray`` -  a `numpy` array of ground-truth labels.
  
       - `y_pred` | `y_score` : ``np.ndarray`` - a `numpy` array of model predictions. This corresponds to              the output of the model.
  
       - `sample_weight`: ``Optional[np.ndarray]`` - a `numpy` array of sample weights.
  
  score_fns
      A literal, or a list or literals, or a score function, or a dictionary of score functions having as keys the
      names of the score functions and as values the score functions (i.e, higher values are better). The
      available literal values are described in :py:data:`alibi.explainers.permutation_importance.SCORE_FNS`.
      As with the `loss_fns`, the `predictor` output must be compatible with every score function and the score
      function must have the same signature presented in the `loss_fns` parameter description.
  feature_names
      A list of feature names used for displaying results.
  verbose
      Whether to print the progress of the explainer.
docstr_tok: ["Initialize","the","permutation","feature","importance",".","Parameters","--","--","--","--","--","predictor","A","prediction","function","which","receives","as","input","a","`","numpy","`","array","of","size","`","N","x","F","`",",","and","outputs","a","`","numpy","`","array","of","size","`","N","`","(","i.e",".","`","(","N",",",")","`",")","or","`","N","x","T","`",",","where","`","N","`","is","the","number","of","input","instances",",","`","F","`","is","the","number","of","features",",","and","`","T","`","is","the","number","of","targets",".","Note","that","the","output","shape","must","be","compatible","with","the","loss","and","score","functions","provided","in","`","loss_fns","`","and","`","score_fns","`",".","loss_fns","A","literal",",","or","a","list","of","literals",",","or","a","loss","function",",","or","a","dictionary","of","loss","functions","having","as","keys","the","names","of","the","loss","functions","and","as","values","the","loss","functions","(","i.e.",",","lower","values","are","better",")",".","The","available","literal","values","are","described","in",":","py",":","data",":","`","alibi.explainers.permutation_importance.LOSS_FNS","`",".","Note","that","the","`","predictor","`","output","must","be","compatible","with","every","loss","function",".","Every","loss","function","is","expected","to","receive","the","following","arguments",":","-","`","y_true","`",":","``","np.ndarray","``","-","a","`","numpy","`","array","of","ground-truth","labels",".","-","`","y_pred","`","|","`","y_score","`",":","``","np.ndarray","``","-","a","`","numpy","`","array","of","model","predictions",".","This","corresponds","to","the","output","of","the","model",".","-","`","sample_weight","`",":","``","Optional","[","np.ndarray","]","``","-","a","`","numpy","`","array","of","sample","weights",".","score_fns","A","literal",",","or","a","list","or","literals",",","or","a","score","function",",","or","a","dictionary","of","score","functions","having","as","keys","the","names","of","the","score","functions","and","as","values","the","score","functions","(","i.e",",","higher","values","are","better",")",".","The","available","literal","values","are","described","in",":","py",":","data",":","`","alibi.explainers.permutation_importance.SCORE_FNS","`",".","As","with","the","`","loss_fns","`",",","the","`","predictor","`","output","must","be","compatible","with","every","score","function","and","the","score","function","must","have","the","same","signature","presented","in","the","`","loss_fns","`","parameter","description",".","feature_names","A","list","of","feature","names","used","for","displaying","results",".","verbose","Whether","to","print","the","progress","of","the","explainer","."]
code: def __init__(
      self,
      predictor: Callable[[np.ndarray], np.ndarray],
      loss_fns: Optional[
          Union[
              LossFnName,
              List[LossFnName],
              Callable[
                  [np.ndarray, np.ndarray, Optional[np.ndarray]], float
              ],
              Dict[
                  str,
                  Callable[
                      [np.ndarray, np.ndarray, Optional[np.ndarray]],
                      float,
                  ],
              ],
          ]
      ] = None,
      score_fns: Optional[
          Union[
              ScoreFnName,
              List[ScoreFnName],
              Callable[
                  [np.ndarray, np.ndarray, Optional[np.ndarray]], float
              ],
              Dict[
                  str,
                  Callable[
                      [np.ndarray, np.ndarray, Optional[np.ndarray]],
                      float,
                  ],
              ],
          ]
      ] = None,
      feature_names: Optional[List[str]] = None,
      verbose: bool = False,
  ):
      """
          Initialize the permutation feature importance.
  
          Parameters
          ----------
          predictor
              A prediction function which receives as input a `numpy` array of size `N x F`, and outputs a
              `numpy` array of size `N` (i.e. `(N, )`) or `N x T`, where `N` is the number of input instances,
              `F` is the number of features, and `T` is the number of targets. Note that the output shape must be
              compatible with the loss and score functions provided in `loss_fns` and `score_fns`.
          loss_fns
              A literal, or a list of literals, or a loss function, or a dictionary of loss functions having as keys the
              names of the loss functions and as values the loss functions (i.e., lower values are better). The available
              literal values are described in :py:data:`alibi.explainers.permutation_importance.LOSS_FNS`. Note that the
              `predictor` output must be compatible with every loss function. Every loss function is expected to receive
              the following arguments:
  
               - `y_true` : ``np.ndarray`` -  a `numpy` array of ground-truth labels.
  
               - `y_pred` | `y_score` : ``np.ndarray`` - a `numpy` array of model predictions. This corresponds to \
               the output of the model.
  
               - `sample_weight`: ``Optional[np.ndarray]`` - a `numpy` array of sample weights.
  
          score_fns
              A literal, or a list or literals, or a score function, or a dictionary of score functions having as keys the
              names of the score functions and as values the score functions (i.e, higher values are better). The
              available literal values are described in :py:data:`alibi.explainers.permutation_importance.SCORE_FNS`.
              As with the `loss_fns`, the `predictor` output must be compatible with every score function and the score
              function must have the same signature presented in the `loss_fns` parameter description.
          feature_names
              A list of feature names used for displaying results.
          verbose
              Whether to print the progress of the explainer.
          """
      super().__init__(
          meta=copy.deepcopy(DEFAULT_META_PERMUTATION_IMPORTANCE)
      )
      self.predictor = predictor
      self.feature_names = feature_names
      self.verbose = verbose
  
      if (loss_fns is None) and (score_fns is None):
          raise ValueError(
              "At least one loss function or a score function must be provided."
          )
  
      # initialize loss and score functions
      self.loss_fns = PermutationImportance._init_metrics(metric_fns=loss_fns, metric_type="loss")  # type: ignore[arg-type] # noqa
      self.score_fns = PermutationImportance._init_metrics(
          metric_fns=score_fns, metric_type="score"
      )
  
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 1 to create a new PermutationImportance object from inherited base classes: Explainer with example: obj = PermutationImportance(predictor, loss_fns, score_fns, feature_names, verbose)