dice_ml package — DiCE 0.7 documentation

# dice_ml package

## Subpackages

- dice_ml.data_interfaces package
  - Submodules
  - dice_ml.data_interfaces.base_data_interface module
  - dice_ml.data_interfaces.private_data_interface module
  - dice_ml.data_interfaces.public_data_interface module
  - Module contents
- dice_ml.explainer_interfaces package
  - Submodules
  - dice_ml.explainer_interfaces.dice_KD module
  - dice_ml.explainer_interfaces.dice_genetic module
  - dice_ml.explainer_interfaces.dice_pytorch module
  - dice_ml.explainer_interfaces.dice_random module
  - dice_ml.explainer_interfaces.dice_tensorflow1 module
  - dice_ml.explainer_interfaces.dice_tensorflow2 module
  - dice_ml.explainer_interfaces.explainer_base module
  - dice_ml.explainer_interfaces.feasible_base_vae module
  - dice_ml.explainer_interfaces.feasible_model_approx module
  - Module contents
- dice_ml.model_interfaces package
  - Submodules
  - dice_ml.model_interfaces.base_model module
  - dice_ml.model_interfaces.keras_tensorflow_model module
  - dice_ml.model_interfaces.pytorch_model module
  - Module contents
- dice_ml.schema package
  - Module contents
- dice_ml.utils package
  - Subpackages
    - dice_ml.utils.sample_architecture package
      - Submodules
      - dice_ml.utils.sample_architecture.vae_model module
      - Module contents
  - Submodules
  - dice_ml.utils.exception module
  - dice_ml.utils.helpers module
  - dice_ml.utils.serialize module
  - Module contents

## Submodules

## dice_ml.constants module

Constants for dice-ml package.

class `dice_ml.constants.` `BackEndTypes`

  Bases: `object`

  `ALL` = ['sklearn', 'TF1', 'TF2', 'PYT']
  `Pytorch` = 'PYT'
  `Sklearn` = 'sklearn'
  `Tensorflow1` = 'TF1'
  `Tensorflow2` = 'TF2'

class `dice_ml.constants.` `ModelTypes`

  Bases: `object`

  `ALL` = ['classifier', 'regressor']
  `Classifier` = 'classifier'
  `Regressor` = 'regressor'

class `dice_ml.constants.` `SamplingStrategy`

  Bases: `object`

  `Genetic` = 'genetic'
  `KdTree` = 'kdtree'
  `Random` = 'random'

## dice_ml.counterfactual_explanations module

class `dice_ml.counterfactual_explanations.` `CounterfactualExplanations`(cf_examples_list, local_importance=None, summary_importance=None, version=None)

  Bases: `object`

  A class to store counterfactual examples for one or more inputs and feature importance scores.

  Parameters

    - cf_examples_list – A list of CounterfactualExamples instances

    - local_importance – List of estimated local importance scores. The size of the list is the number of input instances, each containing feature importance scores for that input.

    - summary_importance – Estimated global feature importance scores based on the input set of CounterfactualExamples instances

  property `cf_examples_list`
  static `from_json`(json_str)

    Deserialize json string to a CounterfactualExplanations object.

  property `local_importance`
  property `metadata`
  property `summary_importance`
  `to_json`()

    Serialize Explanations object to json.

  `visualize_as_dataframe`(display_sparse_df=True, show_only_changes=False)
  `visualize_as_list`(display_sparse_df=True, show_only_changes=False)

## dice_ml.data module

Module pointing to different implementations of Data class

DiCE requires only few parameters about the data such as the range of continuous features and the levels of categorical features. Hence, DiCE can be used for a private data whose meta data are only available (such as the feature names and range/levels of different features) by specifying appropriate parameters.

class `dice_ml.data.` `Data`(**params)

  Bases: `dice_ml.data_interfaces.base_data_interface._BaseData`

  Class containing all required information about the data for DiCE.

  `decide_implementation_type`(params)

    Decides if the Data class is for public or private data.

`dice_ml.data.` `decide`(params)

  Decides if the Data class is for public or private data.

  To add new implementations of Data, add the class in data_interfaces subpackage and import-and-return the class in an elif loop as shown in the below method.

## dice_ml.dice module

Module pointing to different implementations of DiCE based on different frameworks such as Tensorflow or PyTorch or sklearn, and different methods such as RandomSampling, DiCEKD or DiCEGenetic

class `dice_ml.dice.` `Dice`(data_interface, model_interface, method='random', **kwargs)

  Bases: `dice_ml.explainer_interfaces.explainer_base.ExplainerBase`

  An interface class to different DiCE implementations.

  `decide_implementation_type`(data_interface, model_interface, method, **kwargs)

    Decides DiCE implementation type.

`dice_ml.dice.` `decide`(model_interface, method)

  Decides DiCE implementation type.

  To add new implementations of DiCE, add the class in explainer_interfaces subpackage and import-and-return the class in an elif loop as shown in the below method.

## dice_ml.diverse_counterfactuals module

class `dice_ml.diverse_counterfactuals.` `CounterfactualExamples`(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='classifier')

  Bases: `object`

  A class to store and visualize the resulting counterfactual explanations.

  `display_df`(df, show_only_changes)
  static `from_json`(cf_example_json_str)
  `print_list`(li, show_only_changes)
  `to_json`(serialization_version)
  `visualize_as_dataframe`(display_sparse_df=True, show_only_changes=False)
  `visualize_as_list`(display_sparse_df=True, show_only_changes=False)

`dice_ml.diverse_counterfactuals.` `json_converter`(obj)

  Helper function to convert object to json.

## dice_ml.model module

Module pointing to different implementations of Model class

The implementations contain methods to access the output or gradients of ML models trained based on different frameworks such as Tensorflow or PyTorch.

class `dice_ml.model.` `Model`(model=None, model_path='', backend='TF1', model_type='classifier', func=None, kw_args=None)

  Bases: `object`

  An interface class to different ML Model implementations.

  `decide_implementation_type`(model, model_path, backend, func, kw_args)

    Decides the Model implementation type.

`dice_ml.model.` `decide`(backend)

  Decides the Model implementation type.

  To add new implementations of Model, add the class in model_interfaces subpackage and import-and-return the class in an elif loop as shown in the below method.

## Module contents

class `dice_ml.` `Data`(**params)

  Bases: `dice_ml.data_interfaces.base_data_interface._BaseData`

  Class containing all required information about the data for DiCE.

  `decide_implementation_type`(params)

    Decides if the Data class is for public or private data.

class `dice_ml.` `Dice`(data_interface, model_interface, method='random', **kwargs)

  Bases: `dice_ml.explainer_interfaces.explainer_base.ExplainerBase`

  An interface class to different DiCE implementations.

  `decide_implementation_type`(data_interface, model_interface, method, **kwargs)

    Decides DiCE implementation type.

class `dice_ml.` `Model`(model=None, model_path='', backend='TF1', model_type='classifier', func=None, kw_args=None)

  Bases: `object`

  An interface class to different ML Model implementations.

  `decide_implementation_type`(model, model_path, backend, func, kw_args)

    Decides the Model implementation type.