class_docstr: Summarize given metrics on a dataset and model.
  
  Parameters
  ----------
  scorers: Union[Dict[str, Union[Callable, str]], List[Any]] , default: None
      Scorers to override the default scorers (metrics), find more about the supported formats at
      https://docs.deepchecks.com/stable/user-guide/general/metrics_guide.html
  n_to_show : int, default: 20
      Number of classes to show in the report. If None, show all classes.
  show_only : str, default: 'largest'
      Specify which classes to show in the report. Can be one of the following:
      - 'largest': Show the largest classes.
      - 'smallest': Show the smallest classes.
      - 'random': Show random classes.
      - 'best': Show the classes with the highest score.
      - 'worst': Show the classes with the lowest score.
  metric_to_show_by : str, default: None
      Specify the metric to sort the results by. Relevant only when show_only is 'best' or 'worst'.
      If None, sorting by the first metric in the default metrics list.
  class_list_to_show: List[int], default: None
      Specify the list of classes to show in the report. If specified, n_to_show, show_only and metric_to_show_by
      are ignored.
  {additional_check_init_params:2*indent}
class_docstr_tok: ["Summarize","given","metrics","on","a","dataset","and","model",".","Parameters","--","--","--","--","--","scorers",":","Union","[","Dict","[","str",",","Union","[","Callable",",","str","]","]",",","List","[","Any","]","]",",","default",":","None","Scorers","to","override","the","default","scorers","(","metrics",")",",","find","more","about","the","supported","formats","at","https",":","\/\/docs.deepchecks.com\/stable\/user-guide\/general\/metrics_guide.html","n_to_show",":","int",",","default",":","20","Number","of","classes","to","show","in","the","report",".","If","None",",","show","all","classes",".","show_only",":","str",",","default",":","'largest'","Specify","which","classes","to","show","in","the","report",".","Can","be","one","of","the","following",":","-","'largest","'",":","Show","the","largest","classes",".","-","'smallest","'",":","Show","the","smallest","classes",".","-","'random","'",":","Show","random","classes",".","-","'best","'",":","Show","the","classes","with","the","highest","score",".","-","'worst","'",":","Show","the","classes","with","the","lowest","score",".","metric_to_show_by",":","str",",","default",":","None","Specify","the","metric","to","sort","the","results","by",".","Relevant","only","when","show_only","is","'best","'","or","'worst","'",".","If","None",",","sorting","by","the","first","metric","in","the","default","metrics","list",".","class_list_to_show",":","List","[","int","]",",","default",":","None","Specify","the","list","of","classes","to","show","in","the","report",".","If","specified",",","n_to_show",",","show_only","and","metric_to_show_by","are","ignored",".","{","additional_check_init_params:2","*","indent","}"]
docstr: Compute the metric result using the metrics compute method and create display.
docstr_tok: ["Compute","the","metric","result","using","the","metrics","compute","method","and","create","display","."]
code: def compute(self, context: Context) -> CheckResult:
      """Compute the metric result using the metrics compute method and create display."""
      results = []
      for dataset_kind in [DatasetKind.TRAIN, DatasetKind.TEST]:
          dataset = context.get_data_by_kind(dataset_kind)
          metrics_df = metric_results_to_df(
              {
                  k: m.compute()
                  for k, m in self._data_metrics[dataset_kind].items()
              },
              dataset,
          )
          metrics_df["Dataset"] = dataset_kind.value
          labels_per_class = dataset.get_cache()["labels"]
          metrics_df["Number of samples"] = metrics_df[
              "Class Name"
          ].map(labels_per_class.get)
          results.append(metrics_df)
  
      results_df = pd.concat(results)
      results_df = results_df[
          [
              "Dataset",
              "Metric",
              "Class",
              "Class Name",
              "Number of samples",
              "Value",
          ]
      ]
      results_df = results_df.sort_values(
          by=["Dataset", "Value"], ascending=False
      )
  
      if context.with_display:
          if self.class_list_to_show is not None:
              display_df = results_df.loc[
                  results_df["Class"].isin(self.class_list_to_show)
              ]
          elif self.n_to_show is not None:
              rows = results_df["Class"].isin(
                  filter_classes_for_display(
                      results_df,
                      self.metric_to_show_by,
                      self.n_to_show,
                      self.show_only,
                  )
              )
              display_df = results_df.loc[rows]
          else:
              display_df = results_df
  
          fig = (
              px.histogram(
                  display_df,
                  x="Class Name",
                  y="Value",
                  color="Dataset",
                  color_discrete_sequence=(
                      plot.colors["Train"],
                      plot.colors["Test"],
                  ),
                  barmode="group",
                  facet_col="Metric",
                  facet_col_spacing=0.05,
                  hover_data=["Number of samples"],
              )
              .update_xaxes(title="Class", type="category")
              .update_yaxes(title="Value", matches=None)
              .for_each_annotation(
                  lambda a: a.update(text=a.text.split("=")[-1])
              )
              .for_each_yaxis(
                  lambda yaxis: yaxis.update(showticklabels=True)
              )
          )
      else:
          fig = None
  
      return CheckResult(
          results_df, header="Class Performance", display=fig
      )
  
imports: from typing import Any, Callable, Dict, List, Optional, TypeVar, Union
  import pandas
  import plotly.express
  from deepchecks.core import CheckResult, DatasetKind
  from deepchecks.core.check_utils.class_performance_utils import get_condition_class_performance_imbalance_ratio_less_than, get_condition_test_performance_greater_than, get_condition_train_test_relative_degradation_less_than
  from deepchecks.core.errors import DeepchecksValueError
  from deepchecks.utils import plot
  from deepchecks.utils.strings import format_percent
  from deepchecks.vision._shared_docs import docstrings
  from deepchecks.vision.base_checks import TrainTestCheck
  from deepchecks.vision.context import Context
  from deepchecks.vision.metrics_utils.scorers import filter_classes_for_display, get_scorers_dict, metric_results_to_df
  from deepchecks.vision.vision_data.batch_wrapper import BatchWrapper
label_desc: Use image node_id 4 for calling the ClassPerformance obj's underlying member method code with example usage: obj.compute(context) and returns: CheckResult