class_docstr: Unit test Smart Predictor class
class_docstr_tok: ["Unit","test","Smart","Predictor","class"]
docstr: Unit test to_smartexplainer
docstr_tok: ["Unit","test","to_smartexplainer"]
code: def test_to_smartexplainer(self):
      """
      Unit test to_smartexplainer
      """
      predictor_1 = self.predictor_1
  
      data_x = pd.DataFrame(
          {
              "x1": [113, 51, 60, 110, 60],
              "x2": ["S", "M", "S", "D", "M"],
          }
      )
      data_x["id"] = [0, 1, 2, 3, 4]
      data_x = data_x.set_index("id")
      data_x_preprocessed = self.preprocessing_1.transform(data_x)
      data_ypred_init = pd.DataFrame({"ypred": [1, 0, 0, 0, 0]})
      data_ypred_init.index = data_x.index
  
      predictor_1.data = {
          "x": data_x,
          "ypred_init": data_ypred_init,
          "x_preprocessed": data_x_preprocessed,
      }
  
      xpl = predictor_1.to_smartexplainer()
  
      assert (
          str(type(xpl))
          == "<class 'shapash.explainer.smart_explainer.SmartExplainer'>"
      )
      assert xpl.x_encoded.equals(predictor_1.data["x_preprocessed"])
      assert predictor_1.model == xpl.model
      assert predictor_1.backend == xpl.backend
      assert predictor_1.features_dict == xpl.features_dict
      assert predictor_1.label_dict == xpl.label_dict
      assert predictor_1._case == xpl._case
      assert predictor_1._classes == xpl._classes
      assert predictor_1.columns_dict == xpl.columns_dict
      assert predictor_1.preprocessing == xpl.preprocessing
      assert predictor_1.postprocessing == xpl.postprocessing
  
      ct = ColumnTransformer(
          transformers=[
              ("onehot_ce", ce.OrdinalEncoder(), ["x2"]),
          ],
          remainder="passthrough",
      )
      ct.fit(data_x)
  
      predictor_1.preprocessing = ct
      with self.assertRaises(ValueError):
          predictor_1.to_smartexplainer()
  
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 36 for calling the TestSmartPredictor obj's underlying member method code with example usage: obj.test_to_smartexplainer() without return types