class_docstr: Unit test Smart Predictor class
class_docstr_tok: ["Unit","test","Smart","Predictor","class"]
code: def setUp(self):
      df = pd.DataFrame(range(0, 5), columns=["id"])
      df["y"] = df["id"].apply(lambda x: 1 if x < 2 else 0)
      df["x1"] = np.random.randint(1, 123, df.shape[0])
      df["x2"] = ["S", "M", "S", "D", "M"]
      df = df.set_index("id")
      encoder = ce.OrdinalEncoder(cols=["x2"], handle_unknown="None")
      encoder_fitted = encoder.fit(df[["x1", "x2"]])
      df_encoded = encoder_fitted.transform(df[["x1", "x2"]])
      clf = cb.CatBoostClassifier(n_estimators=1).fit(
          df_encoded[["x1", "x2"]], df["y"]
      )
      backend = ShapBackend(model=clf)
  
      columns_dict = {0: "x1", 1: "x2"}
      label_dict = {0: "Yes", 1: "No"}
  
      postprocessing = {
          "x2": {
              "type": "transcoding",
              "rule": {"S": "single", "M": "married", "D": "divorced"},
          }
      }
      features_dict = {"x1": "age", "x2": "family_situation"}
  
      features_types = {
          features: str(df[features].dtypes)
          for features in df[["x1", "x2"]]
      }
  
      self.df_1 = df.copy()
      self.preprocessing_1 = encoder_fitted
      self.df_encoded_1 = df_encoded
      self.clf_1 = clf
      self.backend_1 = backend
      self.columns_dict_1 = columns_dict
      self.label_dict_1 = label_dict
      self.postprocessing_1 = postprocessing
      self.features_dict_1 = features_dict
      self.features_types_1 = features_types
  
      self.predictor_1 = SmartPredictor(
          features_dict,
          clf,
          columns_dict,
          backend,
          features_types,
          label_dict,
          encoder_fitted,
          postprocessing,
      )
  
      self.features_groups = {"group1": ["x1", "x2"]}
      self.features_dict_w_groups = {
          "x1": "age",
          "x2": "weight",
          "group1": "group1",
      }
      self.predictor_1_w_groups = SmartPredictor(
          self.features_dict_w_groups,
          clf,
          columns_dict,
          backend,
          features_types,
          label_dict,
          encoder_fitted,
          postprocessing,
          self.features_groups,
      )
      self.predictor_1.backend.state = SmartState()
      df["x2"] = np.random.randint(1, 100, df.shape[0])
      encoder = ce.OrdinalEncoder(cols=["x2"], handle_unknown="None")
      encoder_fitted = encoder.fit(df[["x1", "x2"]])
      df_encoded = encoder_fitted.transform(df[["x1", "x2"]])
  
      clf = cb.CatBoostClassifier(n_estimators=1).fit(
          df[["x1", "x2"]], df["y"]
      )
      backend = ShapBackend(model=clf)
      features_dict = {"x1": "age", "x2": "weight"}
      features_types = {
          features: str(df[features].dtypes)
          for features in df[["x1", "x2"]].columns
      }
  
      self.df_2 = df.copy()
      self.preprocessing_2 = encoder_fitted
      self.df_encoded_2 = df_encoded
      self.clf_2 = clf
      self.backend_2 = backend
      self.columns_dict_2 = columns_dict
      self.label_dict_2 = label_dict
      self.postprocessing_2 = postprocessing
      self.features_dict_2 = features_dict
      self.features_types_2 = features_types
  
      self.predictor_2 = SmartPredictor(
          features_dict,
          clf,
          columns_dict,
          backend,
          features_types,
          label_dict,
          encoder_fitted,
          postprocessing,
      )
      self.predictor_2.backend.state = SmartState()
  
      df["x1"] = [25, 39, 50, 43, 67]
      df["x2"] = [90, 78, 84, 85, 53]
  
      columns_dict = {0: "x1", 1: "x2"}
      label_dict = {0: "No", 1: "Yes"}
      features_dict = {"x1": "age", "x2": "weight"}
  
      features_types = {
          features: str(df[features].dtypes)
          for features in df[["x1", "x2"]].columns
      }
  
      clf = cb.CatBoostRegressor(n_estimators=1).fit(
          df[["x1", "x2"]], df["y"]
      )
      backend_3 = ShapBackend(model=clf)
  
      self.df_3 = df.copy()
      self.preprocessing_3 = None
      self.df_encoded_3 = df
      self.clf_3 = clf
      self.backend_3 = backend
      self.columns_dict_3 = columns_dict
      self.label_dict_3 = label_dict
      self.postprocessing_3 = None
      self.features_dict_3 = features_dict
      self.features_types_3 = features_types
  
      self.predictor_3 = SmartPredictor(
          features_dict,
          clf,
          columns_dict,
          backend,
          features_types,
          label_dict,
      )
      self.predictor_3.backend.state = SmartState()
  
imports: import unittest
  from shapash.explainer.smart_predictor import SmartPredictor
  from shapash import SmartExplainer
  from shapash.explainer.smart_state import SmartState
  from shapash.explainer.multi_decorator import MultiDecorator
  from shapash.backend import ShapBackend
  import os
  from os import path
  from pathlib import Path
  import pandas
  import numpy
  import catboost
  from catboost import Pool
  import category_encoders
  from unittest.mock import patch
  import types
  from sklearn.compose import ColumnTransformer
  import sklearn.preprocessing
  import shap
label_desc: Use image node_id 1 for calling the TestSmartPredictor obj's underlying member method code with example usage: obj.setUp() without return types