code: def test_tf_keras_adult_explainer(
      disable_tf2,
      adult_data,
      tf_keras_adult_explainer,
      use_kdtree,
      k,
      d_type,
  ):
      model, cf = tf_keras_adult_explainer
      X_train = (
          adult_data["preprocessor"]
          .transform(adult_data["X_train"])
          .toarray()
      )
  
      # instance to be explained
      x = X_train[0].reshape(1, -1)
      pred_class = np.argmax(model.predict(x))
  
      # test fit
      cf.fit(X_train, d_type=d_type)
  
      # checked ragged tensor shape
      n_cat = len(list(cf.cat_vars_ord.keys()))
      max_key = max(cf.cat_vars_ord, key=cf.cat_vars_ord.get)
      max_cat = cf.cat_vars_ord[max_key]
      assert cf.d_abs_ragged.shape == (n_cat, max_cat)
  
      if use_kdtree:  # k-d trees
          assert (
              len(cf.kdtrees) == cf.classes
          )  # each class has a k-d tree
          n_by_class = 0
          for c in range(cf.classes):
              n_by_class += cf.X_by_class[c].shape[0]
          assert (
              n_by_class == X_train.shape[0]
          )  # all training instances are stored in the trees
  
      # test explanation
      explanation = cf.explain(x, k=k)
      if use_kdtree:
          assert cf.id_proto != pred_class
      assert (
          np.argmax(model.predict(explanation.cf["X"]))
          == explanation.cf["class"]
      )
      num_shape = (1, 12)
      assert (
          explanation.cf["grads_num"].shape
          == explanation.cf["grads_graph"].shape
          == num_shape
      )
      assert explanation.meta.keys() == DEFAULT_META_CFP.keys()
      assert explanation.data.keys() == DEFAULT_DATA_CFP.keys()
  
      # test gradient shapes
      y = np.zeros((1, cf.classes))
      np.put(y, pred_class, 1)
      cf.predict = cf.predict.predict  # make model black box
      # convert instance to numerical space
      x_ord = ohe_to_ord(x, cf.cat_vars)[0]
      x_num = ord_to_num(x_ord, cf.d_abs)
      # check gradients
      grads = cf.get_gradients(x_num, y, num_shape[1:], cf.cat_vars_ord)
      assert grads.shape == num_shape
  
file_path: alibi/alibi/explainers/tests/test_cfproto.py
imports: import numpy
  import pytest
  import tensorflow
  from alibi.api.defaults import DEFAULT_META_CFP, DEFAULT_DATA_CFP
  from alibi.explainers import CounterfactualProto
  from alibi.utils.mapping import ohe_to_ord, ord_to_num
label_desc: Use image node_id 4 for calling a global function with example usage: test_tf_keras_adult_explainer(disable_tf2, adult_data, tf_keras_adult_explainer, use_kdtree, k, d_type) without return types