code: def _calc_permutation_importance(
      model: t.Any,
      dataset: "tabular.Dataset",
      model_classes,
      observed_classes,
      task_type,
      n_repeats: int = 30,
      mask_high_variance_features: bool = False,
      random_state: int = 42,
      n_samples: int = 10_000,
      alternative_scorer: t.Optional[DeepcheckScorer] = None,
      skip_messages: bool = False,
      timeout: int = None,
  ) -> pd.Series:
      """Calculate permutation feature importance. Return nonzero value only when std doesn't mask signal.
  
      Parameters
      ----------
      model: t.Any
          A fitted model
      dataset: tabular.Dataset
          dataset used to fit the model
      model_classes
          possible classes output for model. None for regression tasks.
      observed_classes
          Observed classes in the data. None for regression tasks.
      task_type
          The task type of the model.
      n_repeats: int, default: 30
          Number of times to permute a feature
      mask_high_variance_features : bool , default: False
          If true, features for which calculated permutation importance values
          varied greatly would be returned has having 0 feature importance
      random_state: int, default: 42
          Random seed for permutation importance calculation.
      n_samples: int, default: 10_000
          The number of samples to draw from X to compute feature importance
          in each repeat (without replacement).
      alternative_scorer: t.Optional[DeepcheckScorer], default: None
          Scorer to use for evaluation of the model performance in the permutation_importance function. If not defined,
          the default deepchecks scorers are used.
      skip_messages: bool, default: False
          If True will not print any message related to timeout or calculation.
      timeout: int, default: None
          Allowed runtime of permutation_importance, in seconds. As we can't limit the actual runtime of the function,
          the timeout parameter is used for estimation of the runtime, done be measuring the inference time of the model
          and multiplying it by number of repeats and features. If the expected runtime is bigger than timeout, the
          calculation is skipped.
  
      Returns
      -------
      pd.Series
          feature importance normalized to 0-1 indexed by feature names
      """
      if not dataset.has_label():
          raise errors.DatasetValidationError(
              "Expected dataset with label."
          )
  
      if len(dataset.features) == 1:
          return pd.Series([1], index=dataset.features)
  
      dataset_sample = dataset.sample(
          n_samples, random_state=random_state
      ).drop_na_labels()
  
      # Test score time on the dataset sample
      if alternative_scorer:
          scorer = alternative_scorer
      else:
          default_scorers = get_default_scorers(task_type)
          scorer_name = next(iter(default_scorers))
          single_scorer_dict = {
              scorer_name: default_scorers[scorer_name]
          }
          scorer = init_validate_scorers(
              single_scorer_dict,
              model,
              dataset,
              model_classes,
              observed_classes,
          )[0]
  
      start_time = time.time()
      scorer(model, dataset_sample)
      calc_time = time.time() - start_time
  
      predicted_time_to_run = (
          int(np.ceil(calc_time * n_repeats * len(dataset.features)))
          or 1
      )
  
      if timeout is not None:
          if predicted_time_to_run > timeout:
              raise errors.DeepchecksTimeoutError(
                  f"Skipping permutation importance calculation: calculation was projected to finish in "
                  f"{predicted_time_to_run} seconds, but timeout was configured to {timeout} seconds"
              )
          elif not skip_messages:
              get_logger().info(
                  "Calculating permutation feature importance. Expected to finish in %s seconds",
                  predicted_time_to_run,
              )
      elif timeout == 0 and not skip_messages:
          raise errors.DeepchecksSkippedFeatureImportance(
              "feature_importance_timeout set to 0. Skipping any feature importance calculation."
          )
      elif not skip_messages:
          get_logger().warning(
              "Calculating permutation feature importance without time limit. Expected to finish in "
              "%s seconds",
              predicted_time_to_run,
          )
  
      r = permutation_importance(
          model,
          dataset_sample.features_columns,
          dataset_sample.label_col,
          n_repeats=n_repeats,
          random_state=random_state,
          n_jobs=-1,
          scoring=scorer.scorer,
      )
  
      significance_mask = (
          r.importances_mean - r.importances_std > 0
          if mask_high_variance_features
          else r.importances_mean > 0
      )
  
      feature_importance = r.importances_mean * significance_mask
      total = feature_importance.sum()
  
      if total != 0:
          feature_importance = feature_importance / total
  
      return pd.Series(feature_importance, index=dataset.features)
  
imports: import time
  import typing
  import warnings
  import numpy
  import pandas
  from sklearn.inspection import permutation_importance
  from sklearn.pipeline import Pipeline
  from deepchecks import tabular
  from deepchecks.core import errors
  from deepchecks.core.errors import DeepchecksValueError
  from deepchecks.tabular.metric_utils.scorers import DeepcheckScorer, get_default_scorers, init_validate_scorers
  from deepchecks.tabular.utils.task_type import TaskType
  from deepchecks.tabular.utils.validation import validate_model
  from deepchecks.utils.logger import get_logger
  from deepchecks.utils.typing import Hashable
label_desc: Use image node_id 4 for calling a global function with example usage: _calc_permutation_importance(model, dataset, model_classes, observed_classes, task_type, n_repeats, mask_high_variance_features, random_state, n_samples, alternative_scorer, skip_messages, timeout) and returns: pd, pd