code: def test_counterfactual_vary_features(
      self,
      vary_all_features,
      feature_importance,
      encode_target_as_strings,
  ):
      (
          X_train,
          X_test,
          y_train,
          y_test,
          feature_names,
          _,
      ) = create_iris_data()
      if encode_target_as_strings:
          y_train = y_train.astype(str)
          y_test = y_test.astype(str)
  
      model = create_lightgbm_classifier(X_train, y_train)
      X_train["target"] = y_train
      X_test["target"] = y_test
  
      rai_insights = RAIInsights(
          model=model,
          train=X_train,
          test=X_test.iloc[0:10],
          target_column="target",
          task_type="classification",
      )
  
      if vary_all_features:
          features_to_vary = "all"
      else:
          features_to_vary = [feature_names[0]]
  
      rai_insights.counterfactual.add(
          total_CFs=10,
          desired_class=2,
          features_to_vary=features_to_vary,
          feature_importance=feature_importance,
      )
      rai_insights.counterfactual.compute()
  
      cf_obj = rai_insights.counterfactual.get()[0]
      assert cf_obj is not None
      for index in range(0, len(cf_obj.cf_examples_list)):
          assert (
              isinstance(
                  cf_obj.cf_examples_list[index]
                  .test_instance_df["target"]
                  .values[0],
                  str,
              )
              == encode_target_as_strings
          )
  
          assert cf_obj.cf_examples_list[index].test_instance_df[
              "target"
          ].values[0] in set(y_train)
  
          cf_target_array = (
              cf_obj.cf_examples_list[0].final_cfs_df["target"].values
          )
          for inner_index in range(0, 10):
              assert (
                  isinstance(cf_target_array[inner_index], str)
                  == encode_target_as_strings
              )
              assert cf_target_array[inner_index] in set(y_train)
  
file_path: responsible-ai-toolbox/responsibleai/tests/counterfactual/test_counterfactual_advanced_features.py
imports: import os
  import pytest
  from rai_test_utils.models.lightgbm import create_lightgbm_classifier
  from raiutils.exceptions import UserConfigValidationException
  from responsibleai import RAIInsights
  from responsibleai._interfaces import CounterfactualData
  from responsibleai._internal.constants import FileFormats
  from responsibleai._tools.shared.state_directory_management import DirectoryManager
  from ..common_utils import create_iris_data
label_desc: Use image node_id 1 for calling the TestCounterfactualAdvancedFeatures obj's underlying member method code with example usage: obj.test_counterfactual_vary_features(vary_all_features, feature_importance, encode_target_as_strings) without return types