docstr: Calculate all metrics in _all_metrics.
docstr_tok: ["Calculate","all","metrics","in","_all_metrics","."]
code: def _calculate_metrics(
      self, X, labels, ground_truth=None, ml_usecase=None
  ) -> dict:
      """
      Calculate all metrics in _all_metrics.
      """
      from pycaret.utils.generic import calculate_unsupervised_metrics
  
      if ml_usecase is None:
          ml_usecase = self._ml_usecase
  
      try:
          return calculate_unsupervised_metrics(
              metrics=self._all_metrics,
              X=X,
              labels=labels,
              ground_truth=ground_truth,
          )
      except Exception:
          if ml_usecase == MLUsecase.CLUSTERING:
              metrics = get_all_metric_containers(self.variables, True)
          return calculate_unsupervised_metrics(
              metrics=metrics,  # type: ignore
              X=X,
              labels=labels,
              ground_truth=ground_truth,
          )
  
imports: import datetime
  import gc
  import logging
  import time
  import traceback
  from typing import Any, Callable, Dict, List, Optional, Union
  import numpy
  import pandas
  from joblib.memory import Memory
  from sklearn.base import clone
  from pycaret.containers.metrics.clustering import get_all_metric_containers
  from pycaret.containers.models.clustering import ALL_ALLOWED_ENGINES, get_container_default_engines
  from pycaret.internal.display import CommonDisplay
  from pycaret.internal.logging import get_logger, redirect_output
  from pycaret.internal.pipeline import Pipeline
  from pycaret.internal.pipeline import estimator_pipeline, get_pipeline_fit_kwargs
  from pycaret.internal.preprocess.preprocessor import Preprocessor
  from pycaret.internal.pycaret_experiment.tabular_experiment import _TabularExperiment
  from pycaret.internal.validation import is_sklearn_pipeline
  from pycaret.loggers.base_logger import BaseLogger
  from pycaret.utils.constants import DATAFRAME_LIKE, SEQUENCE_LIKE
  from pycaret.utils.generic import MLUsecase, highlight_setup
label_desc: Use image node_id 2 for calling the _UnsupervisedExperiment obj's underlying member method code with example usage: obj._calculate_metrics(X, labels, ground_truth, ml_usecase) and returns: calculate_unsupervised_metrics, calculate_unsupervised_metrics