Code Monkey home page Code Monkey logo

bellatrex's Introduction

Bellatrex Logo

Welcome to Bellatrex!

Random Forest models can be difficult to interpret, and Bellatrex addresses this challenge by generating explanations that are easy to understand, and by providing insights into how the model arrived at its predictions. Bellatrex does so by Building Explanations through a LocalLy AccuraTe Rule EXtractor (hence the name: Bellatrex) for a given test instance, by extracting only a few, diverse rules. See the published paper for more details.

To illustrate how Bellatrex works, let's consider an example: when a user provides a test instance to Bellatrex, the tool begins by 1) pre-selecting a subset of the rules used to make the prediction; it then creates 2) a vector representation of such rules and 3) projects them to a low-dimensional space; Bellatrex then 4) clusters such representations to pick a rule from each cluster to explain the instance prediction. One rule per cluster is shown to the end user through visually appealing plots, and the tool's GUI allows users to explore similar rules to those extracted.

Bellatrex image
Overview representation of Bellatrex, starting from top left, proceeding clockwise, we reach the output and explanation on the bottom left.

Another strength of Bellatrex lies in its ability to handle several prediction tasks within scikit-learn implementations of Random Forests. For instance, Bellatrex can generate explanations for binary classification and multi-label predictions tasks with RandomForestClassifier, as well as single- or multi-output regression tasks with RandomForestRegressor. Moreover, Bellatrex is compatible with scikit-survival's RandomSurvivalForest, allowing it to generate explanations for time-to-event predictions in the presence of right-censored data.

This repository contains:

  • instructions to run Bellatrex on your machine
  • an overwview of the datasets used to test the effectiveness of the method
  • accesss to such datasets, as they appear after the pre-processing step.

Set-up

To ensure that Bellatrex runs correctly, use a Python environment that matches the requirements indicated in requirements.txt. To minimize the chances of encountering compatibility issues, we advice to install the packages on a new (conda) environment with Anaconda:

conda create --name bellatrex-tutorial python=3.10

activate the environment and proceed by installing the packages listed in the requirements.txt file, namely:

conda install scikit-learn==1.2.2
conda install scikit-survival==0.21.0
conda install matplotlib==3.8.0

The scikit-survival package allows to run time-to-event predictions with RandomSurvivalForest. In case of errors it can also be installed by executing the command conda install -c sebp scikit-survival=0.21. Install the Orange library with conda install orange3==3.30 to replicate the statistical tests reported in the manuscript.

Enable Graphical User Interface

For an enhanced user experience that includes interactive plots, install the following packages through pip (not available on Anaconda):

pip install dearpygui==1.6.2 
pip install dearpygui-ext==0.9.5

To then make use of the Graphical User Interface, set the variable SET_PLOT_GUI equal toTrue to change the value of the plot_GUI attribute on a Bellatrex instance.

Note: When running Bellatrex with the GUI for multiple test samples, the program will generate an interactive window. The process may take a couple of seconds, and the the user has to click at least once within the generated window in order to activate the interactive mode. Once this is done, the user can explore the generated rules by clicking on the corresponding representation. To show the Bellatrex explanation for the next sample, close the interactive window and wait until Bellatrex generates the explanation for the new sample.

Ready for the tutorial!

If you have downloaded the content of this folder and installed the packages successfully, you can dive into the tutorial.ipynb code and try Bellatrex yourself!

bellatrex's People

Contributors

klest94 avatar robbedhondt avatar

Stargazers

 avatar Antoine Weisrock avatar Nin Khodorivsko avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

robbedhondt

bellatrex's Issues

Error running `tutorial.ipynb`

Following up on #3, I tried to run the tutorial provided in the tutorial.ipynb Jupyter Notebook. I was able to follow it successfully until the very last cell, that unfortunately crashes when executed. It gives me the following exception:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[8], line 11
      7 preds_distr = np.load("example-data/bin_tutorial_y_train_preds.npy")
      8 axs = plot_rules(rules, preds, baselines, weights, 
      9             max_rulelen=None, other_preds=other_preds, preds_distr=preds_distr,
     10 )
---> 11 axs[0].set_xlim([0,1])
     12 # plt.savefig("visualisation.pdf")

AttributeError: 'numpy.ndarray' object has no attribute 'set_xlim'

As indicated, the error seems to be that the axs variable is treated as an array of matplotlib.axes.Axes, whereas it is actually an array of array of matplotlib.axes.Axes. I guess the problem comes from 1ff6da6, where the following change occurred in visualisation.py (around line 199):

-    return axs
+    return aaxs

Replacing axs[0] with axs[0, 0] in the tutorial fixed the issue and successfully plotted a graph. I'm not sure if it's the tutorial that needs to be updated or the value returned by the plot_rules function.

Cheers,
Weis

`README` not up to date

Hi there !

I tried to follow the instructions given in the README.md file for testing the module, but it failed right from the start with the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<string>", line 7, in <module>
ModuleNotFoundError: No module named 'utilities'

The problematic lines seem to be these ones:

Bellatrex/README.md

Lines 75 to 76 in e56ec80

from utilities import score_method, output_X_y
from utilities import format_targets, format_RF_preds

I guess that this part of README.md was never updated since 69351d0.
My intent is just to bring it to your attention, as tutorial.ipynb seems the be the new correct way to follow the tutorial (although that is nowhere mentioned).

Cheers,
Weis

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.