carla-recourse / carla Goto Github PK
View Code? Open in Web Editor NEWCARLA: A Python Library to Benchmark Algorithmic Recourse and Counterfactual Explanation Algorithms
License: MIT License
CARLA: A Python Library to Benchmark Algorithmic Recourse and Counterfactual Explanation Algorithms
License: MIT License
The current implementation of CEM does not allow to train an autoencoder while calling it.
This leads to errors when no pretrained autoencoder is available.
__version__
to packageAlso check out this guide: https://realpython.com/pypi-publish-python-package/
Similar to the benchmarking process at https://github.com/Philoso-Fish/Benchmarkin_Counterfactual_Examples implement the evaluation to repeat the experiments from the KDD paper.
AR for linear models does not need LIME. Coefficients and Intercepts are passed through parameter.
The current output of CEM will not work with the benchmarking process.
Expand Dice model to work with VAE
What about imputers?
Do you have any recommendation or best practice for address them?
Implement the CEM method similar to the implementation at https://github.com/Philoso-Fish/Benchmarkin_Counterfactual_Examples
There are two variations of CEM to implement
Add extensive test cases
The original Github repository can either be found asking Martin or in the old repository at CF_Models/cem_ml
Thank you for all the work you put into the CARLA package. It's a great help when trying to compare different counterfactual methods! My questions pertain the parameters/specifications used in the CARLA paper.
What was the train/test split for the ann model? Do you have a way to access the train/test data in the package so that I can fit my own model with the same data?
In the paper, the adult data set seems to fix the features age, sex, and race. However, in the dataset class, Datacatalog("adult").immutables gives only "age" and "sex" as the immutables. Can you comment on whether there was a change since the simulations in the paper were run or whether the default in the package is wrong?
I am getting an error when running the cem/cem-vae models. When running:
mlmodel = MLModelCatalog(dataset, "ann", backend)
CEM(factuals, mlmodel, hyperparams)
where hyperparams comes from the experimental_setup.yaml script, I get the following error:
ValueError: For hidden_layer is no default value defined, please pass this key and its value in hyperparams
Changing the hyperparameters "ae_params" dictionary to:
hyperparams["ae_params"] = {'hidden_layer': [20, 10, 7], 'train_ae': True, 'epochs': 5}
does the trick. Can you let me know if this is the same hidden_layer dimension used in the paper?
The give_me_some_credit data set models the response "SeriousDlqin2yrs" which is a negative response. However, the predict_negative_instances() function returns factuals as those with a predicted probability of less than 0.5 (specifically 1675 rows). I would argue that these are the positive instances and the negative instances have a probability of lower than 0.5. Do you have any comment about this?
Finally, are the results in Table 2 of the paper based on all factuals with a predicted probability less than 0.5 (i.e., 1675 rows for give_me_some_credit and 39954 rows for adult)?
Thanks for all of your help!
Annabelle
Until now, every call of run_experiment saves its results in cache. It would be good if we could define an argpars for individual save paths.
Implement the DICE method similar to the implementation at https://github.com/Philoso-Fish/Benchmarkin_Counterfactual_Examples
Add extensive test cases
Similar to data catalog, use a yaml file to configure feature order
Improve the graph search method of Face, such that it can deal with continuous features.
However, authors also do not mention how to go about it
Implement the FACE method similar to the implementation at https://github.com/Philoso-Fish/Benchmarkin_Counterfactual_Examples
There are two variations of FACE to implement
Add extensive test cases
The original Github repository can either be found asking Martin or in the old repository at CF_Models/face_ml
The L0 distance for CLUE is computed with a factual and counterfactual list of 21 entries, rather then 14. Probably the one_hot_encoding that causes this.
The MLModelCatalog predict method has the following signature:
def predict(
self, x: Union[np.ndarray, pd.DataFrame, torch.Tensor, tf.Tensor]
) -> Union[np.ndarray, pd.DataFrame, torch.Tensor, tf.Tensor]:
however if the MLModelCatalog pipeline is enabled then x is also input for
def perform_pipeline(self, df: pd.DataFrame) -> pd.DataFrame:
i.e. the predict function can take input types that are incompatible with the possible model settings.
Some documentation left from the old function parameters
In the get_counterfactuals method in CEM binary_cols
is used. Is this the same as data.categoricals
?
Also there is also a method map_binary_backto_string
, this is implemented differently in the new api right?
We recently published Neural Additive Models (NAMs) at NeurIPS 2021 which combines the interpretability of generalized additive models with neural nets (see the architecture shown below). We also evaluated NAMs on some of the dataset here including COMPAS and adult. Do you think they'd make for a good addition in this repo too?
The source code for NAMs is open-sourced in tensorflow (official version) and pytorch!
For a quick summary of NAMs, look at this thread.
Implement the AR method similar to the implementation at https://github.com/Philoso-Fish/Benchmarkin_Counterfactual_Examples
Add extensive test cases
Hi,
When I tried to use the benchmark to test the constraint violations, I find an inaccurate casting in violations.py
Line 34. When casting a float to an int using astype
, we can get some inaccurate results which will break the constraint_violation check. Instead, we should use round
before typecasting
.
For example:
df_decoded_cfs[model.data.continous] = pd.DataFrame.round(df_decoded_cfs[
model.data.continous
]).astype(
"int64"
)
In https://carla-counterfactual-and-recourse-library.readthedocs.io/en/latest/examples.html there are @property
tags missing.
E.g.
def feature_input_order(self):
return [...]
should be
@property
def feature_input_order(self):
return [...]
Given the problem between correct normalization, encoding, and feature order, which is specific to a certain, arbitrary black-box model, we need to have a setter method for class properties encoded, normalized, and encoded_normalized.
This method can use the black-box model and its pipeline as input to build the required dataframes.
Construct a documentation page with our docstring via Sphinx and integrate it via Github Pages
If a mlmodel is trained with use_pipeline = False
then normalizing when calling predict_negative_instances
seems to result in an error.
For example, if someone loads first the tensorflow ann model into cache at '../Users/xxx/carla/models/ann/adult/ann.h5' then it is not possible to load the pytorch model as ann.pt into the same directory.
Even the directory already exists, the if-condition
if not os.path.exists(cache_path):
would not recognize it, since the new file ann.pt is not contained. Creating the path would lead to an error.
Hi!
Just a quick clarification question about the code used to calculate yNN. I noticed that the the labels of the closest neighbours (neighbour_label) in nearest_neighbours.py is compared to something called 'cf_label' which is defined as
cf_label = row[mlmodel.data.target]
If I'm not mistaken, cf_label is then the TRUE label of the test observation (not the predicted label).
This seems to be different from what is written under 4.2 "yNN" in the arXiv paper. Do you think it should be the predicted label and not the TRUE label that should be compared instead?
Thanks for your help.
It is currently not possible to load a pytorch model which was saved in the banchmarking repsitory.
To load such a model it is necessary to have access to the original class, as discussed here and here.
Loading it without access to the class causes the error ModuleNotFound Error: No module named 'ML_Model'
The current adult dataset contains still nan values.
Fix preprocessing and lose unknown data.
Implement the remaining measurements used in https://github.com/Philoso-Fish/Benchmarkin_Counterfactual_Examples
An update in the h5py package causes errors in model loading for Tensorflow architectures (Link)
To successfully load our tensrflow model we need h5py version 2.10.0
We want the functions to be immutable & deterministc and not enforce the caller to have to use dataframes.
predict_negative_instances
calls 'predict_label' which normalized the input, and calls 'model.predict'. If 'model.use_pipeline==True' then 'model.predict' again normalizes the data, resulting in double normalization.
Keep the model structure and training of AE inside CARLA and train a model, if it is needed inside a recourse method. After Training, the model is saved in our cache and can be loaded from there, if the recourse method is called another time.
The training doesn't take long, so we don't need to keep trained models in a repository.
Implement the CLUE method similar to the implementation at https://github.com/Philoso-Fish/Benchmarkin_Counterfactual_Examples
Add extensive test cases
The original Github repository can either be found asking Martin or in the old repository at CF_Models/clue_ml.
CLUE needs a pytorch model, maybe solving issue #16 is crucial for this.
It's probably better to either use Sigmoid with BCELoss or Softmax with CELoss.
With this one: #81 we have documentation hosted on read-the-docs, now we want an automated build that pushes to it. According to @Philoso-Fish requires a github webhook that can be retrieved via the admin interface
The hyperparams parameter needs a generalized method to check if every important key is inside the input, and eventually assign default values.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.