class_docstr: Abstract class with common methods to be inherited by WeakSegmentsPerformance checks.
class_docstr_tok: ["Abstract","class","with","common","methods","to","be","inherited","by","WeakSegmentsPerformance","checks","."]
code: def _create_heatmap_display(
      self,
      data: pd.DataFrame,
      weak_segments: pd.DataFrame,
      avg_score: float,
      score_per_sample: Optional[pd.Series] = None,
      label_col: Optional[pd.Series] = None,
      dummy_model: Optional[_DummyModel] = None,
      scorer: Optional[DeepcheckScorer] = None,
      scorer_name: Optional[str] = None,
  ):
      display_tabs = {}
      if scorer_name is None and scorer is None:
          score_title = "Average Score Per Sample"
      else:
          score_title = (
              scorer_name
              if scorer_name is not None
              else scorer.name + " Score"
          )
      temp_col = "temp_label_column"
      if (
          label_col is not None
      ):  # add label col to data for filtering purposes
          data[temp_col] = label_col
  
      idx = -1
      while len(display_tabs.keys()) < self.n_to_show and idx + 1 < len(
          weak_segments
      ):
          idx += 1
          segment = weak_segments.iloc[idx, :]
          feature1 = data[segment["Feature1"]]
  
          # Bin the rest of the data into data segments based on the features used to create the weak segment
          if segment["Feature2"] != "":
              feature2 = data[segment["Feature2"]]
              segments_f1 = partition_numeric_feature_around_segment(
                  feature1, segment["Feature1 Range"]
              )
              segments_f2 = partition_numeric_feature_around_segment(
                  feature2, segment["Feature2 Range"]
              )
          else:  # if only one feature is used to create the weak segment
              feature2 = pd.Series(np.ones(len(feature1)))
              segments_f1 = partition_numeric_feature_around_segment(
                  feature1, segment["Feature1 Range"], 7
              )
              segments_f2 = [0, 2]
  
          # Calculate the score for each of the bins defined above
          scores = np.empty(
              (len(segments_f2) - 1, len(segments_f1) - 1), dtype=float
          )
          counts = np.empty(
              (len(segments_f2) - 1, len(segments_f1) - 1), dtype=int
          )
          for f1_idx in range(len(segments_f1) - 1):
              for f2_idx in range(len(segments_f2) - 1):
                  segment_data = data[
                      np.asarray(
                          feature1.between(
                              segments_f1[f1_idx],
                              segments_f1[f1_idx + 1],
                          )
                      )
                      * np.asarray(
                          feature2.between(
                              segments_f2[f2_idx],
                              segments_f2[f2_idx + 1],
                          )
                      )
                  ]
                  if segment_data.empty:
                      scores[f2_idx, f1_idx] = np.NaN
                      counts[f2_idx, f1_idx] = 0
                  else:
                      if (
                          scorer is not None
                          and dummy_model is not None
                          and label_col is not None
                      ):
                          scores[
                              f2_idx, f1_idx
                          ] = scorer.run_on_data_and_label(
                              dummy_model,
                              segment_data.drop(columns=temp_col),
                              segment_data[temp_col],
                          )
                      else:
                          scores[f2_idx, f1_idx] = score_per_sample[
                              list(segment_data.index)
                          ].mean()
                      counts[f2_idx, f1_idx] = len(segment_data)
  
          f1_labels = self._format_partition_vec_for_display(
              segments_f1, segment["Feature1"]
          )
          f2_labels = self._format_partition_vec_for_display(
              segments_f2, segment["Feature2"]
          )
  
          scores_text = [
              [0] * scores.shape[1] for _ in range(scores.shape[0])
          ]
          counts = np.divide(counts, len(data))
          for i in range(len(f2_labels)):
              for j in range(len(f1_labels)):
                  score = scores[i, j]
                  if not np.isnan(score):
                      scores_text[i][
                          j
                      ] = f"{format_number(score)}\n({format_percent(counts[i, j])})"
                  elif counts[i, j] == 0:
                      scores_text[i][j] = ""
                  else:
                      scores_text[i][
                          j
                      ] = f"{score}\n({format_percent(counts[i, j])})"
  
          # Plotly FigureWidget have bug with numpy nan, so replacing with python None
          scores = scores.astype(object)
          scores[np.isnan(scores.astype(float))] = None
  
          labels = dict(
              x=segment["Feature1"],
              y=segment["Feature2"],
              color=score_title,
          )
          fig = px.imshow(
              scores,
              x=f1_labels,
              y=f2_labels,
              labels=labels,
              color_continuous_scale="rdylgn",
          )
          fig.update_traces(text=scores_text, texttemplate="%{text}")
          if segment["Feature2"]:
              title = f"{score_title} (percent of data)"
              tab_name = (
                  f'{segment["Feature1"]} vs {segment["Feature2"]}'
              )
          else:
              title = f"{score_title} (percent of data)"
              tab_name = segment["Feature1"]
          fig.update_layout(
              title=title,
              height=600,
              xaxis_showgrid=False,
              yaxis_showgrid=False,
          )
  
          msg = (
              f"Check ran on {data.shape[0]} data samples. {score_title} on the full data set "
              f"is {format_number(avg_score)}."
          )
          display_tabs[tab_name] = [fig, msg]
  
      return display_tabs
  
imports: import abc
  from collections import defaultdict
  from typing import Any, Callable, Dict, List, Optional, Tuple, Union
  import numpy
  import pandas
  import plotly.express
  import sklearn
  from category_encoders import TargetEncoder
  from packaging import version
  from sklearn.model_selection import GridSearchCV
  from sklearn.tree import DecisionTreeRegressor
  from deepchecks import ConditionCategory, ConditionResult
  from deepchecks.tabular import Dataset
  from deepchecks.tabular.context import _DummyModel
  from deepchecks.tabular.metric_utils.scorers import DeepcheckScorer
  from deepchecks.utils.dataframes import default_fill_na_per_column_type
  from deepchecks.utils.performance.partition import DeepchecksFilter, convert_tree_leaves_into_filters, partition_numeric_feature_around_segment
  from deepchecks.utils.strings import format_number, format_percent
label_desc: Use image node_id 2 for calling the WeakSegmentAbstract obj's underlying member method code with example usage: obj._create_heatmap_display(data, weak_segments, avg_score, score_per_sample, label_col, dummy_model, scorer, scorer_name) and returns: display_tabs