class_docstr: A class to store and visualize the resulting counterfactual explanations.
class_docstr_tok: ["A","class","to","store","and","visualize","the","resulting","counterfactual","explanations","."]
code: def __init__(
      self,
      data_interface=None,
      final_cfs_df=None,
      test_instance_df=None,
      final_cfs_df_sparse=None,
      posthoc_sparsity_param=0,
      desired_range=None,
      desired_class="opposite",
      model_type=ModelTypes.Classifier,
  ):
      self.data_interface = data_interface
      self.final_cfs_df = final_cfs_df
      self.test_instance_df = test_instance_df
      self.final_cfs_df_sparse = final_cfs_df_sparse
      self.model_type = model_type
      self.desired_class = desired_class
      self.desired_range = desired_range
  
      self.final_cfs_list = None
      self.posthoc_sparsity_param = (
          posthoc_sparsity_param  # might be useful for future additions
      )
  
      self.test_pred = self.test_instance_df[
          self.data_interface.outcome_name
      ].iat[0]
      if model_type == ModelTypes.Classifier:
          if desired_class == "opposite":
              self.new_outcome = 1.0 - round(self.test_pred)
          else:
              self.new_outcome = desired_class
      elif model_type == ModelTypes.Regressor:
          self.new_outcome = desired_range
  
imports: import copy
  import json
  import math
  import numpy
  import pandas
  from dice_ml.constants import ModelTypes, _SchemaVersions
  from dice_ml.utils.serialize import DummyDataInterface
label_desc: Use image node_id 1 to create a new CounterfactualExamples object  with example: obj = CounterfactualExamples(data_interface, final_cfs_df, test_instance_df, final_cfs_df_sparse, posthoc_sparsity_param, desired_range, desired_class, model_type)