code: def _calculate_feature_importance(
      model: t.Any,
      dataset: t.Union["tabular.Dataset", pd.DataFrame],
      model_classes,
      observed_classes,
      task_type,
      force_permutation: bool = False,
      permutation_kwargs: t.Dict[str, t.Any] = None,
  ) -> t.Tuple[pd.Series, str]:
      """Calculate features effect on the label.
  
      Parameters
      ----------
      model : t.Any
          a fitted model
      dataset : t.Union['tabular.Dataset', pd.DataFrame]
          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.
      force_permutation : bool, default: False
          force permutation importance calculation
      permutation_kwargs : t.Dict[str, t.Any] , default: None
          kwargs for permutation importance calculation
  
      Returns
      -------
      Tuple[Series, str]:
          first item - feature importance normalized to 0-1 indexed by feature names,
          second item - type of feature importance calculation (types: `permutation_importance`,
          `feature_importances_`, `coef_`)
  
      Raises
      ------
      NotFittedError
          Call 'fit' with appropriate arguments before using this estimator.
      DeepchecksValueError
          if model validation failed.
          if it was not possible to calculate features importance.
      NumberOfFeaturesLimitError
          if the number of features limit were exceeded.
      """
      if task_type == TaskType.REGRESSION:
          model_classes = None
          observed_classes = None
  
      permutation_kwargs = permutation_kwargs or {}
      permutation_kwargs["random_state"] = permutation_kwargs.get(
          "random_state", 42
      )
      validate_model(dataset, model)
      permutation_failure = None
      calc_type = None
      importance = None
  
      if force_permutation:
          if isinstance(dataset, pd.DataFrame):
              raise errors.DeepchecksValueError(
                  "Cannot calculate permutation feature importance on a pandas Dataframe. "
                  "In order to force permutation feature importance, please use the Dataset"
                  " object."
              )
          else:
              importance = _calc_permutation_importance(
                  model,
                  dataset,
                  model_classes,
                  observed_classes,
                  task_type,
                  **permutation_kwargs,
              )
              calc_type = "permutation_importance"
  
      # If there was no force permutation, or if it failed while trying to calculate importance,
      # we don't take built-in importance in pipelines because the pipeline is changing the features
      # (for example one-hot encoding) which leads to the inner model features
      # being different from the original dataset features
      if importance is None and not isinstance(model, Pipeline):
          # Get the actual model in case of pipeline
          importance, calc_type = _built_in_importance(model, dataset)
          # If found importance and was force permutation failure before, show warning
          if importance is not None and permutation_failure:
              get_logger().warning(permutation_failure)
  
      # If there was no permutation failure and no importance on the model, using permutation anyway
      if (
          importance is None
          and permutation_failure is None
          and isinstance(dataset, tabular.Dataset)
      ):
          if not permutation_kwargs.get("skip_messages", False):
              if isinstance(model, Pipeline):
                  pre_text = "Cannot use model's built-in feature importance on a Scikit-learn Pipeline,"
              else:
                  pre_text = "Could not find built-in feature importance on the model,"
              get_logger().warning(
                  "%s using permutation feature importance calculation instead",
                  pre_text,
              )
  
          importance = _calc_permutation_importance(
              model,
              dataset,
              model_classes,
              observed_classes,
              task_type,
              **permutation_kwargs,
          )
          calc_type = "permutation_importance"
  
      # If after all importance is still none raise error
      if importance is None:
          # FIXME: better message
          raise errors.DeepchecksValueError(
              "Was not able to calculate features importance"
          )
      return importance.fillna(0), calc_type
  
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 2 for calling a global function with example usage: _calculate_feature_importance(model, dataset, model_classes, observed_classes, task_type, force_permutation, permutation_kwargs) and returns: importance,  calc_type