dice_ml.data_interfaces package

Submodules

dice_ml.data_interfaces.base_data_interface module

Module containing base class for data interfaces for dice-ml.

dice_ml.data_interfaces.private_data_interface module

Module containing meta data information about private data.

class dice_ml.data_interfaces.private_data_interface.PrivateData(params)[source]

Bases: _BaseData

A data interface for private data with meta information.

create_ohe_params(one_hot_encoded_data=None)[source]
de_normalize_data(df)[source]

De-normalizes continuous features from [0,1] range to original range.

fit_label_encoders()[source]
from_dummies(data, prefix_sep='_')[source]

Gets the original data from dummy encoded data with k levels.

from_label(data)[source]

Transforms label encoded data back to categorical values

get_all_dummy_colnames()[source]
get_data_params_for_gradient_dice()[source]

Gets all data related params for DiCE.

get_decimal_precisions(output_type='list')[source]

“Gets the precision of continuous features in the data.

get_decoded_data(data, encoding='one-hot')[source]

Gets the original data from encoded data.

get_encoded_categorical_feature_indexes()[source]

Gets the column indexes categorical features after one-hot-encoding.

get_features_range(permitted_range_input=None, features_dict=None)[source]
get_indexes_of_features_to_vary(features_to_vary='all')[source]

Gets indexes from feature names of one-hot-encoded data.

get_inverse_ohe_min_max_normalized_data(transformed_data)[source]

Transforms one-hot-encoded and min-max normalized data into raw user-fed data format. transformed_data should be a dataframe or an array

get_mads(normalized=True)[source]

Computes Median Absolute Deviation of features.

get_minx_maxx(normalized=True)[source]

Gets the min/max value of features in normalized or de-normalized form.

get_ohe_min_max_normalized_data(query_instance)[source]

Transforms query_instance into one-hot-encoded and min-max normalized data. query_instance should be a dict, a dataframe, a list, or a list of dicts

get_valid_feature_range(feature_range_input, normalized=True)[source]

Gets the min/max value of features in normalized or de-normalized form. Assumes that all features are already encoded to numerical form such that the number of features remains the same.

# TODO needs work adhere to label encoded max and to support permitted_range for both continuous and discrete when provided in _generate_counterfactuals.

get_valid_mads(normalized=False, display_warnings=False, return_mads=True)[source]

Computes Median Absolute Deviation of features. If they are <=0, returns a practical value instead

normalize_data(df)[source]

Normalizes continuous features to make them fall in the range [0,1].

one_hot_encode_data(data)[source]

One-hot-encodes the data.

prepare_df_for_ohe_encoding()[source]

Create base dataframe to do OHE for a single instance or a set of instances

prepare_query_instance(query_instance)[source]

Prepares user defined test input(s) for DiCE.

query_instance_to_df(query_instance)[source]

dice_ml.data_interfaces.public_data_interface module

Module containing all required information about the interface between raw (or transformed) public data and DiCE explainers.

class dice_ml.data_interfaces.public_data_interface.PublicData(params)[source]

Bases: _BaseData

A data interface for public data. This class is an interface to DiCE explainers and contains methods to transform user-fed raw data into the format a DiCE explainer requires, and vice versa.

create_ohe_params(one_hot_encoded_data)[source]
de_normalize_data(df)[source]

De-normalizes continuous features from [0,1] range to original range.

fit_label_encoders()[source]
from_dummies(data, prefix_sep='_')[source]

Gets the original data from dummy encoded data with k levels.

from_label(data)[source]

Transforms label encoded data back to categorical values

get_all_dummy_colnames()[source]
get_data_params_for_gradient_dice()[source]

Gets all data related params for DiCE.

get_data_type(col)[source]

Infers data type of a continuous feature from the training data.

get_decimal_precisions(output_type='list')[source]

“Gets the precision of continuous features in the data.

get_decoded_data(data, encoding='one-hot')[source]

Gets the original data from encoded data.

get_encoded_categorical_feature_indexes()[source]

Gets the column indexes categorical features after one-hot-encoding.

get_features_range(permitted_range_input=None, features_dict=None)[source]
get_indexes_of_features_to_vary(features_to_vary='all')[source]

Gets indexes from feature names of one-hot-encoded data.

get_inverse_ohe_min_max_normalized_data(transformed_data)[source]

Transforms one-hot-encoded and min-max normalized data into raw user-fed data format. transformed_data should be a dataframe or an array

get_mads(normalized=False)[source]

Computes Median Absolute Deviation of features.

get_minx_maxx(normalized=True)[source]

Gets the min/max value of features in normalized or de-normalized form.

get_ohe_min_max_normalized_data(query_instance)[source]

Transforms query_instance into one-hot-encoded and min-max normalized data. query_instance should be a dict, a dataframe, a list, or a list of dicts

get_quantiles_from_training_data(quantile=0.05, normalized=False)[source]

Computes required quantile of Absolute Deviations of features.

get_valid_feature_range(feature_range_input, normalized=True)[source]

Gets the min/max value of features in normalized or de-normalized form. Assumes that all features are already encoded to numerical form such that the number of features remains the same.

# TODO needs work adhere to label encoded max and to support permitted_range for both continuous and discrete when provided in _generate_counterfactuals.

get_valid_mads(normalized=False, display_warnings=False, return_mads=True)[source]

Computes Median Absolute Deviation of features. If they are <=0, returns a practical value instead

normalize_data(df)[source]

Normalizes continuous features to make them fall in the range [0,1].

one_hot_encode_data(data)[source]

One-hot-encodes the data.

prepare_df_for_ohe_encoding()[source]

Create base dataframe to do OHE for a single instance or a set of instances

prepare_query_instance(query_instance)[source]

Prepares user defined test input(s) for DiCE.

Module contents