class_docstr: Unit test Smart Predictor class
class_docstr_tok: ["Unit","test","Smart","Predictor","class"]
docstr: Unit test 2 of detail_contributions method.
docstr_tok: ["Unit","test","2","of","detail_contributions","method","."]
code: def test_detail_contributions_2(self):
      """
      Unit test 2 of detail_contributions method.
      """
      clf = cb.CatBoostRegressor(n_estimators=1).fit(
          self.df_2[["x1", "x2"]], self.df_2["y"]
      )
      predictor_1 = self.predictor_1
  
      predictor_1.model = clf
      predictor_1.backend = ShapBackend(model=clf)
      predictor_1.preprocessing = None
      predictor_1.backend._case = "regression"
      predictor_1._case = "regression"
      predictor_1._classes = None
  
      predictor_1.data = {
          "x": None,
          "ypred": None,
          "contributions": None,
          "x_preprocessed": None,
      }
      predictor_1.data["x"] = self.df_2[["x1", "x2"]]
      predictor_1.data["x_preprocessed"] = self.df_2[["x1", "x2"]]
      predictor_1.data["ypred_init"] = pd.DataFrame(self.df_2["y"])
  
      contributions = predictor_1.detail_contributions()
  
      assert contributions.shape[0] == predictor_1.data["x"].shape[0]
      assert all(contributions.index == predictor_1.data["x"].index)
      assert (
          contributions.shape[1] == predictor_1.data["x"].shape[1] + 1
      )
  
      clf = cb.CatBoostClassifier(n_estimators=1).fit(
          self.df_2[["x1", "x2"]], self.df_2["y"]
      )
      backend = ShapBackend(model=clf)
  
      predictor_1 = self.predictor_2
      predictor_1.preprocessing = None
      predictor_1.model = clf
      predictor_1.backend = backend
      predictor_1._case = "classification"
      predictor_1._classes = [0, 1]
  
      false_y = pd.DataFrame({"y_false": [2, 2, 1, 1, 1]})
      predictor_1.data = {
          "x": None,
          "ypred": None,
          "contributions": None,
      }
      predictor_1.data["x_preprocessed"] = self.df_2[["x1", "x2"]]
      predictor_1.data["x"] = self.df_2[["x1", "x2"]]
      predictor_1.data["ypred_init"] = false_y
  
      with self.assertRaises(ValueError):
          predictor_1.detail_contributions()
  
      predictor_1.data["ypred_init"] = pd.DataFrame(self.df_2["y"])
  
      contributions = predictor_1.detail_contributions()
  
      assert contributions.shape[0] == predictor_1.data["x"].shape[0]
      assert all(contributions.index == predictor_1.data["x"].index)
      assert (
          contributions.shape[1] == predictor_1.data["x"].shape[1] + 2
      )
  
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 23 for calling the TestSmartPredictor obj's underlying member method code with example usage: obj.test_detail_contributions_2() without return types