code: def test_cf_explainer_iris(disable_tf2, cf_iris_explainer):
      X, y, lr, cf = cf_iris_explainer
      x = X[0].reshape(1, -1)
      probas = cf.predict_fn(x)
      pred_class = probas.argmax()
  
      assert cf.data_shape == (1, 4)
  
      # test explanation
      exp = cf.explain(x)
      assert exp.meta.keys() == DEFAULT_META_CF.keys()
      assert exp.data.keys() == DEFAULT_DATA_CF.keys()
  
      x_cf = exp.cf["X"]
      assert x.shape == x_cf.shape
  
      probas_cf = cf.predict_fn(x_cf)
      pred_class_cf = probas_cf.argmax()
  
      # get attributes for testing
      target_class = cf.target_class
      target_proba = cf.sess.run(cf.target_proba)
      tol = cf.tol
      pred_class_fn = cf.predict_class_fn
  
      # check if target_class condition is met
      if target_class == "same":
          assert pred_class == pred_class_cf
      elif target_class == "other":
          assert pred_class != pred_class_cf
      elif isinstance(target_class, int):
          assert pred_class_cf == target_class
  
      if exp.success:
          assert np.abs(pred_class_fn(x_cf) - target_proba) <= tol
  
file_path: alibi/alibi/explainers/tests/test_counterfactual.py
imports: import pytest
  import numpy
  from sklearn.datasets import load_iris
  from sklearn.linear_model import LogisticRegression
  import tensorflow
  from alibi.api.defaults import DEFAULT_META_CF, DEFAULT_DATA_CF
  from alibi.explainers.counterfactual import _define_func
  from alibi.explainers import Counterfactual
label_desc: Use image node_id 5 for calling a global function with example usage: test_cf_explainer_iris(disable_tf2, cf_iris_explainer) without return types