Dice ml documentation example Changing feature weights that decide relative importance of features in perturbation Below we show an example where DiCE uses only basic metadata about each feature used in the ML model. Slicing and dicing our data. html at main · interpretml/DiCE Diverse Counterfactual Explanations (DiCE) for ML; Notebooks: Quick introduction to generating counterfactual explanations using DiCE; Estimating local and global feature importance scores using DiCE; Generating counterfactuals for multi-class classification and regression models; Regression; Generating counterfactual explanations with any ML model Here is an example script of a DiCE initialization of our trained model. Then I w Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community. Quick introduction to generating counterfactual explanations using DiCE. The core idea is to setup finding such explanations as an optimization problem, similar import dice_ml from dice_ml. - DiCE/docs/dice_ml. When the training dataset is unknown (e. We'll be explaining both regression and classification models. Enterprises DiCE_model_agnostic_CFs. pipeline import Pipeline from sklearn. Here is a snippet: dice_exp_genetic = exp_genetic. Previous Next . model_selection import train_test_split dataset = helpers. preprocessing import Computes the Dice loss value between y_true and y_pred. - sci-m-wang/T-COL Sep 2, 2020 · Can I generate more than 4 counterfactual explanations with the Dice package? All Dice examples have exactly 4 counterfactual explanations via the "total_CFs=4" code. I play a lot of Warhammer 40k, a dice-based tabletop board game, and enjoy watching live-streamed tournament games on Twitch. Good documentation has many benefits and is one of the highest ROI steps that a company can take. Hi, I've trained DICE with a k-nn classifier, and want to generate counterfactuals for a test set from the same dataset. py" inside the subpackage dice_ml. new_outcome = desired_range def __eq__ (self, other_counterfactual_example): dice_ml. dice_interfaces. html at main · interpretml/DiCE DICE SEARCH AND BOOLEAN STRINGS words, it emphasizes using data fields with unique attributes (a. A decent streaming setup for 40k usually includes two top-down cameras: one for viewing the entire table, and one aimed at a For more details, check out the docs/source/notebooks folder. For convenience, we include the sample trained model with the DiCE package. Below we show an example where DiCE uses only basic metadata about each feature used in the ML model. compose import ColumnTransformer from sklearn. x """ import collections import copy import random import timeit import numpy as np import tensorflow as tf from dice_ml import diverse_counterfactuals as exp from dice_ml. Dice(d,model) d = dice_ml. For example, switching two one-hot-encoded features to 1 when in reality the entity can't exist in this state (e. You switched accounts on another tab or window. explainer_interfaces package; dice_ml. It works fine for most instances in the test set, but for others, it remains stuck indefinitely (see screenshot belo Hello everyone, I am looking for a way to export the generated examples to something like a pandas-dataframe. Maybe, I am missing something but I tried to do so for sometime now but could not find a solution. Download and Prepare Data. compute_dist (x_hat, x1) [source] Compute weighted distance between two vectors. n”, “n”, “Note that we need to specify the explainer in the model backend. model_selection import train_test_split from sklearn. This tool is intended as a way to subdivide extremely large features that cause issues with drawing, analysis, editing, and/or performance but are difficult to split up with standard editing and geoprocessing tools. columns. Data(dataframe=Data, continuous_features=[], categorical_features=[], outcome_name='') identifying all categorical features in the model before inputting it into the dice instance. """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""" from raiutils. We'll start by dividing How to explain a machine learning model such that the explanation is truthful to the model and yet interpretable to people? The main objective of DiCE is to explain the predictions For example, we could use DiCE to generate counterfactual explanations for why a particular passenger survived or died. This is because both model and explainer need to be using the same backend library Documentation GitHub Skills Blog Solutions By company size. Model(model_path=ML_modelpath, backend=backend, func="ohe-min Diverse Counterfactual Explanations (DiCE) for ML Typically, the company may provide an explanation on why the loan was rejected, for example, due to “poor credit history”. utils import helpers # helper functions # Tensorflow libraries import tensorflow as tf # supress deprecation warnings from TF tf. Local and Machine Learning (ML) is a type of artificial intelligence (AI) whereby software will analyze data, and from there make predictions based on that data. """Module containing all required information about the interface between raw (or transformed) public data and DiCE explainers. DiCE can dice_ml. yml file generated by AutoML. class dice_ml. First, we will load the data into a standard pandas dataframe or a numpy array, and create a train / test split. data_interfaces. First of all, let load the Iris dataset then the dataset is split into training and test set in order to prepare it in the training phase. Let’s walk through an example of each using the UCI adult income classification dataset. dice_ml. - DiCE/docs/index. Data(dataframe = df_train, continuous_features = df_train. We made minor modifications to the original code, primarily altering the stopping condition in the counterfactual search from prediction=[0, 1] to prediction=[0,1,0] to account for the additional Jun 7, 2024 · Overview; LogicalDevice; LogicalDeviceConfiguration; PhysicalDevice; experimental_connect_to_cluster; experimental_connect_to_host; experimental_functions_run_eagerly Oct 14, 2024 · Hi cynicdog, Greetings & Welcome to Microsoft Q&A forum! Thanks for posting your query! We understand that you are facing deployment failures due to version conflicts in the conda. This is because both model and explainer need to be using the same backend library (pytorch or tensorflow). load_adult_income_dataset () For example, the following input leads to Generating counterfactual explanations with any ML model; Generating counterfactual explanations without access to training data; Advanced options to customize Counterfactual Explanations; Package: dice_ml package. g. public_data_interface. v1. x. schema package Module contents . Moreover, a simple 1-nearest neighbor model trained on the gener-ated CF examples obtains comparable accuracy on locally approxi-mating the original ML model to methods like LIME [32], which are directly optimized for estimating the local decision boundary. Defaults to random. . explainer Nov 22, 2024 · “That’s it! You can try generating counterfactual explanations for other examples using the same code. For this example we’ll use the Drug Review Dataset that’s hosted on the UC Irvine Machine For the counterfactual experiment, we used the CARLA and DiCE-ML libraries. Subclasses implement interfaces for different ML DiCE is part of the broader InterpretML library, and is great at generating “Diverse Counterfactual Explanations” for a particular dataset. Data(dataframe=train_dataset, continuous_features=['Age', 'Fare'], {"payload":{"allShortcutsEnabled":false,"fileTree":{"docs":{"items":[{"name":"_images","path":"docs/_images","contentType":"directory"},{"name":"_modules","path import copy import json import math import numpy as np import pandas as pd from dice_ml. ("user manual" OR "manual" OR "documentation" OR "user documentation" OR presentation) AND ("microsoft office" OR HTML OR Javascript How to explain a machine learning model such that the explanation is truthful to the model and yet interpretable to people? Ramaravind K. explainer_interfaces. Tversky loss: Tversky loss is proposed as a robust loss function that can be used to handle imbalanced Apr 17, 2024 · """ Module to generate diverse counterfactual explanations based on tensorflow 1. ; Create explanations using the Use pip install dice_ml to install DiCE. A common example of an object is a user account on a website. Model(model=ann_model) >>> m <dice_ml. To address the deployment failure you’re experiencing, I recommend specifying the same image version that successfully worked for you previously, Jan 23, 2023 · CF examples with substantially higher diversity for these datasets. 5-turbo, GPT-4, Ernie-4, Qwen, GLM-4, Gemini) powered by LangGPT framework. desired_range: For regression problems, identify the desired range of outcomes. KerasTensorFlowModel'> But I am not able to create the background data instance, as outcome_name is not used in my case. The confusion is that this page in the documentation states that the user can pass a parameter called feature_weights, which is a dictionary with weights for each feature. conda-forge - the place where the feedstock and smithy live and work to produce the finished article (built conda distributions) import dice_ml from dice_ml import Dice from sklearn. Subpackages. I want to predict whether students will drop out of school in the next week based on the data of the previous few weeks. ensemble import For example, DiCE (Diverse Counterfactual Explanations) generates a set of diverse feature-perturbed options for the same person whose loan gets rejected but would have gotten approved if the income increased by $10,000 or income increased by $5,000 and have 1 more year of credit history. DiCE optimizes for both diversity and proximity to the Jun 26, 2023 · Dice loss: Dice loss is also a measure of the overlap between the predicted mask and the ground truth mask. Model() instance with actual trained model. exceptions import UserConfigValidationException from sklearn. tolist()) In case of For more details, check out the docs/source/notebooks folder. explainer_interfaces, then backend parameter should be {"model": "xgboost_model. Here are some example notebooks: Getting Started: Generate CF examples for a sklearn, tensorflow or pytorch binary classifier and compute feature importance For instance, if there is a model interface class "XGBoostModel" in module "xgboost_model. So if your model has these two functions, you can use it with the "sklearn" backend. logging. However, such an explanation does not help the person decide what they should do next to improve their chances of being approved in the future. Changing "total_CFs" to different numbers will cause errors as well. exceptions import UserConfigValidationException from dice_ml. Optional string or integer. Hi,I have a question there, so I hope to get some help. You signed out in another tab or window. Similar to Pandas, 🤗 Datasets provides several functions to manipulate the contents of Dataset and DatasetDict objects. XGBoostModel", You signed in with another tab or window. Just use the backend="sklearn" and input the lightgbm model. The model is now stored as a DiCE model for explanation purposes: >>> m = dice_ml. It's my first time using dice, thanks so much for your help! For more details, check out the docs/source/notebooks folder. I am trying to fix it using this command as suggested above, but adjusted to feedstock - the conda recipe (raw material), supporting scripts and CI configuration. Overview; Machine Learning Based Estimation of Heterogeneous Treatment Effects Hi, @CESARDELATORRE, I am getting this exact issue again, in Azure ML. 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. Instead, that method supports other 'weight' parameters: @konabuta DiCE supports any ML model that respects the scikit-learn API for predict and predict_proba. In this case, what it’s reflecting is that there is a higher Dec 13, 2020 · Hi, @CESARDELATORRE, I am getting this exact issue again, in Azure ML. Case Studies: Towards Data Science (Hotel Bookings) | Analytics Vidhya InterpretML supports training interpretable models (glassbox), as well as explaining existing ML pipelines (blackbox). preprocessing import StandardScaler, OneHotEncoder from sklearn. You signed in with another tab or window. We already encountered the Dataset. constants import BackEndTypes, SamplingStrategy from dice_ml. T Apr 17, 2024 · Quick introduction to generating counterfactual explanations using DiCE Estimating local and global feature importance scores using DiCE Generating counterfactuals for multi-class classification and regression models Apr 28, 2024 · Example Gallery¶ This gallery contains a collection of best practice code snippets together with their corresponding video/image output, illustrating different functionalities all across the library. 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 DiCE requires two inputs: a training dataset and a pre-trained ML model. ; Create dice_ml. generate_counterfactuals(query_instances, total_CFs=4, desired_class='opposite', verbose=True) That's why the dice-ml explainer probably calculated the counterfactuals for adding a categorical_features variable to the DICE dataset from exp = dice_ml. These are all under Nov 22, 2024 · “That’s it! You can try generating counterfactual explanations for other examples using the same code. FAT* ‘20 paper I encountered this issue too. utils. Model(model=ann_model, Saved searches Use saved searches to filter your results more quickly import copy import json import math import numpy as np import pandas as pd from dice_ml. model_interfaces. dice_tensorflow1 module Module to generate diverse counterfactual explanations based on tensorflow 1. Welcome to econml’s documentation! EconML User Guide. For more details, check out the docs/source/notebooks folder. Preliminaries: Loading a dataset and a ML model trained over it; Generating counterfactual examples using DiCE; Generating feature attributions (local and global) using DiCE; Working with deep learning models (TensorFlow and PyTorch) More resources: What’s next? For instance, if there is a model interface class "XGBoostModel" in module "xgboost_model. keras_tensorflow_model. Generate Diverse Counterfactual Explanations for any machine learning model. """ from numpy. get_adult_income_modelpath(backend=backend) m = dice_ml. DiceTensorFlow1 (data_interface, model_interface) [source] Bases: ExplainerBase. data {"payload":{"allShortcutsEnabled":false,"fileTree":{"docs":{"items":[{"name":"_images","path":"docs/_images","contentType":"directory"},{"name":"_modules","path For demonstration purposes, we transform the data as described in dice_ml. dice_tensorflow1. Install Learn Develop web ML applications in JavaScript TensorFlow Lite Deploy ML on mobile, microcontrollers and other edge devices make_parse_example_spec; numeric_column; sequence_categorical_column_with_hash_bucket; Write better code with AI Code review. model_interfaces package; dice_ml We find that our proposed method outperforms current methods for generating a diverse set of counterfactuals. counterfactual_explanations import CounterfactualExplanations from dice_ml. utils import helpers # TF2 ML_modelpath = helpers. Dice() instance with data and model instances created in the previous two steps. in Generalised Dice overlap as a deep learning loss function for highly unbalanced segmentations Edit \begin{equation} DiceLoss\left( y, \overline{p} \right) = 1 - \dfrac{\left( 2y\overline . Explaining Multi-class Classifiers and Regressors: Generate CF explanations for a multi-class classifier or regressor. d = dice_ml. map() method in Chapter 3, and in this section we’ll explore some of the other functions at our disposal. Defaults to 0. I use a dateset about MOOC, and I use a LSTM model. k. Dice Loss Introduced by Sudre et al. a. FAT* '20 paper | Docs | Example Notebooks | Live Jupyter notebook . Create dice_ml. ” , “exp = dice_ml. We also discover an impressive property of counterfactuals: just a handful of counterfactual explanations are Diverse Counterfactual Explanations (DiCE) for ML; Notebooks: Quick introduction to generating counterfactual explanations using DiCE; Estimating local and global feature importance scores using DiCE; Generating counterfactuals for multi-class classification and regression models; Regression; Generating counterfactual explanations with any ML The process for creating a counterfactual explanation using dice-ml consists of a few simple steps as mentioned below. serialize import DummyDataInterface class _DiverseCFV1SchemaConstants: Regressor: self. KerasTensorFlowModel at 0x7f22fb2e0da0> As previously mentioned, the features are now stored in a special format compatible with DiCE Advanced options to customize Counterfactual Explanations . ERROR) [ ]: For convenience, we include the sample trained model with the DiCE package. I am trying to fix it using this command as suggested above, but adjusted to Aug 2, 2024 · 237 “appoint”referstochangesinpersonnel, mainly ontheboardofdirectors,andcorrespondsto“low” impactlevelsintermsofESG. I think and hope that this i The dice-ml explainer to use. it can be red or blue, but it cannot be both). html at main · interpretml/DiCE Diverse Counterfactual Explanations (DiCE) for ML; Notebooks: Quick introduction to generating counterfactual explanations using DiCE; Estimating local and global feature importance scores using DiCE; Generating counterfactuals for multi-class classification and regression models; Regression; Generating counterfactual explanations with any ML model Unfortunately, documentation of pipelines is one of the most overlooked aspects of Machine Learning. Data() instance with background data. datasets import load_iris, fetch_california_housing from sklearn. Nov 22, 2024 · The above feature weights encode that changing age is approximately seven times more difficult than changing categorical variables, and changing hours_per_week is approximately three times more difficult than changing age. random import seed # import DiCE import dice_ml from dice_ml. Here we discuss a few ways to change DiCE’s behavior. """ import logging from collections import defaultdict import numpy as np import pandas as pd from raiutils. I think LightGBM uses an API that is compatible with scikit-learn, so I think it should work. ensemble import RandomForestClassifier import dice_ml from dice_ml import Dice from dice_ml. from sklearn. Here are some example notebooks: Getting Started: Generate CF examples for a sklearn, tensorflow or pytorch binary classifier and compute feature importance scores. XGBoostModel", I don't think dice-ml should generate counterfactuals when it can't find valid ones. I am using a default suggested compute node, STANDARD_DS12_V2 created on May 29, 2022 2:30 PM. For 330 points it might take close to 3 mintues. Is it possible for you to share notebook and data set? I can try to reproduce and debug where dice-ml is taking longer. Either random, genetic, or kdtree. Model(model_path=ML_modelpath, backend=backend, func="ohe-min Diverse Counterfactual Explanations (DiCE) for ML How to explain a machine learning model such that the explanation is truthful to the model and yet interpretable to people? Ramaravind K. new_outcome = desired_range def __eq__ (self, other_counterfactual_example): For example, with the emergence of cloud services some people don’t need to care about network, server and storage to some extent. [1]: # import DiCE import pandas as pd import dice_ml from dice_ml. Train a custom ML model. Over time, the app will find patterns, and make more accurate predictions not unlike the way humans will learn over time. objects) rather than logic or functions. You can compare the running time of this VAE-based to DiCE’s default method: VAE-based method is super fast!n”, “n”, “## Adding feasibility constraintsn”, “However, you might notice that for some examples, the above method can still return infeasible Nov 22, 2024 · dice_ml. Blog Post: Explanation for ML using diverse counterfactuals. Manage code changes Generate Diverse Counterfactual Explanations for any machine learning model. set_verbosity(tf. compat. explainer_base module Module containing a template class to generate counterfactual explanations. Its primary use is in the construction of the CI . <class 'dice_ml. Formally, such “what-if” data points are known as counterfactuals, described by the following question: The DiCE library provides an easy interface to generate such counterfactual examples for any ML model. Local and Source: Jupyter Notebook. You can compare the running time of this VAE-based to DiCE’s default method: VAE-based method is super fast!n”, “n”, “## Adding feasibility constraintsn”, “However, you might notice that for some examples, the above method can still return infeasible counterfactuals. constants import ModelTypes, _SchemaVersions from dice_ml. Of course, this may sound odd, since a person cannot change their age. The DiCE library helps you to understand an ML model by generating “what-if” data points that lead to the desired model output. © Copyright 2020, Ramaravind, Amit, Chenhao. “That’s it! You can try generating counterfactual explanations for other examples using the same code. With DiCE, generating explanations is a simple three-step process: set up a dataset, train a model, and then invoke DiCE to generate counterfactual examples for any input. Counterfactual Calculations. The final group of words focuses on specific Apr 17, 2024 · Quick introduction to generating counterfactual explanations using DiCE Estimating local and global feature importance scores using DiCE Generating counterfactuals for multi-class classification and regression models Counterfactual Explanation generation methods, using Tree-based Conditions Optional Links and Large Language Models (like GPT-3. yml files and simplify the management of many feedstocks. As new data comes in, the predictions are compared against results, which are added to the data. Local and Project Goal: Use deep learning to detect and classify six-sided dice from images, mobile devices, and (eventually) video. You need a dataset, model Discover how DICE-ML enhances understanding of machine learning models with diverse counterfactual explanations, improving transparency and bias detection. data_interfaces package; dice_ml. Dice(d, m, encoded_size=10, lr=1e-2, batch_size=2048,n Source code for dice_ml. utils import helpers # helper functions from sklearn. dice-ml takes roughly 0. Mothilal, Amit Sharma, Chenhao Tan. utils import helpers # helper functions Saved searches Use saved searches to filter your results more quickly """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. Now convert data Generate Diverse Counterfactual Explanations for any machine learning model. ipynb example. Subdivides a feature into smaller features based on a specified vertex limit. However, as pointed out, this is not actually implemented in generate_counterfactuals. desired_class: Index identifying the desired counterfactual class. 5 second to generate counterfactuals for one query point. m = dice_ml. Reload to refresh your session. conda-smithy - the tool which helps orchestrate the feedstock. helpers module. For binary classification, this should be set to opposite. model_interfaces, and dice interface class "DiceXGBoost" in module "dice_xgboost" inside dice_ml. In this case, what it’s reflecting is that there is a higher diversity in age values than Is dice-ml able to generate CFs for one point or 10 points? It seems like you are using 330 points. The source code for these libraries is already included in the src/ folder, so no additional setup is required. The above feature weights encode that changing age is approximately seven times more difficult than changing categorical variables, and changing hours_per_week is approximately three times more difficult than changing age. You can compare the running time of this VAE-based to DiCE’s default method: VAE-based method is super fast!n”, “n”, “## Adding feasibility constraintsn”, “However, you might notice that for some examples, the above method can still return infeasible Apr 16, 2024 · Summary. , for privacy reasons), it can also work without access to the full As a part of this section, we'll explain how we can use dice-ml to generate counterfactual examples for Keras/Tensorflow models. By “Diverse Counterfactual Explanations”, we mean decisions made by a model DiCE is based on recent research that generates CF explanations for any ML model. Optional string. No- Stay informed on the latest trending ML papers with code, research developments, libraries, methods, and datasets. uxce hooq invzz noro fntxh llfi edith jxay amghth fxvaub