Home

Awesome

<p align="center"> <img src="https://raw.githubusercontent.com/MAIF/shapash/master/docs/_static/shapash-resize.png" width="300" title="shapash-logo"> </p> <p align="center"> <!-- Tests --> <a href="https://github.com/MAIF/shapash/workflows/Build%20%26%20Test/badge.svg"> <img src="https://github.com/MAIF/shapash/workflows/Build%20%26%20Test/badge.svg" alt="tests"> </a> <!-- PyPi --> <a href="https://img.shields.io/pypi/v/shapash"> <img src="https://img.shields.io/pypi/v/shapash" alt="pypi"> </a> <!-- Downloads --> <a href="https://static.pepy.tech/personalized-badge/shapash?period=total&units=international_system&left_color=grey&right_color=orange&left_text=Downloads"> <img src="https://static.pepy.tech/personalized-badge/shapash?period=total&units=international_system&left_color=grey&right_color=orange&left_text=Downloads" alt="downloads"> </a> <!-- Python Version --> <a href="https://img.shields.io/pypi/pyversions/shapash"> <img src="https://img.shields.io/pypi/pyversions/shapash" alt="pyversion"> </a> <!-- License --> <a href="https://img.shields.io/pypi/l/shapash"> <img src="https://img.shields.io/pypi/l/shapash" alt="license"> </a> <!-- Doc --> <a href="https://shapash.readthedocs.io/en/latest/"> <img src="https://readthedocs.org/projects/shapash/badge/?version=latest" alt="doc"> </a> </p>

🔍 Overview

Shapash is a Python library designed to make machine learning interpretable and comprehensible for everyone. It offers various visualizations with clear and explicit labels that are easily understood by all.

With Shapash, you can generate a Webapp that simplifies the comprehension of interactions between the model's features, and allows seamless navigation between local and global explainability. This Webapp enables Data Scientists to effortlessly understand their models and share their results with both data scientists and non-data experts.

Additionally, Shapash contributes to data science auditing by presenting valuable information about any model and data in a comprehensive report.

Shapash is suitable for Regression, Binary Classification and Multiclass problems. It is compatible with numerous models, including Catboost, Xgboost, LightGBM, Sklearn Ensemble, Linear models, and SVM. For other models, solutions to integrate Shapash are available; more details can be found here.

[!NOTE] If you want to give us feedback : Feedback form

Shapash App Demo

<p align="center"> <img src="https://raw.githubusercontent.com/MAIF/shapash/master/docs/_static/shapash_global.gif" width="800"> </p>

🌱 Documentation and resources

🎉 What's new ?

VersionNew FeatureDescriptionTutorial
2.3.xAdditional dataset columns <br> New demo <br> ArticleIn Webapp: Target and error columns added to dataset and possibility to add features outside the model for more filtering options<img src="https://raw.githubusercontent.com/MAIF/shapash/master/docs/_static/add_column_icon.png" width="50" title="add_column">
2.3.xIdentity card <br> New demo <br> ArticleIn Webapp: New identity card to summarize the information of the selected sample<img src="https://raw.githubusercontent.com/MAIF/shapash/master/docs/_static/identity_card.png" width="50" title="identity">
2.2.xPicking samples <br> ArticleNew tab in the webapp for picking samples. The graph represents the "True Values Vs Predicted Values"<img src="https://raw.githubusercontent.com/MAIF/shapash/master/docs/_static/picking.png" width="50" title="picking">
2.2.xDataset Filter <br>New tab in the webapp to filter data. And several improvements in the webapp: subtitles, labels, screen adjustments<img src="https://raw.githubusercontent.com/MAIF/shapash/master/docs/_static/webapp.png" width="50" title="webapp">
2.0.xRefactoring Shapash <br>Refactoring attributes of compile methods and init. Refactoring implementation for new backends<img src="https://raw.githubusercontent.com/MAIF/shapash/master/docs/_static/modular.png" width="50" title="modular">
1.7.xVariabilize Colors <br>Giving possibility to have your own colour palette for outputs adapted to your design<img src="https://raw.githubusercontent.com/MAIF/shapash/master/docs/_static/variabilize-colors.png" width="50" title="variabilize-colors">
1.6.xExplainability Quality Metrics <br> ArticleTo help increase confidence in explainability methods, you can evaluate the relevance of your explainability using 3 metrics: Stability, Consistency and Compacity<img src="https://raw.githubusercontent.com/MAIF/shapash/master/docs/_static/quality-metrics.png" width="50" title="quality-metrics">
1.4.xGroups of features <br> DemoYou can now regroup features that share common properties together. <br>This option can be useful if your model has a lot of features.<img src="https://raw.githubusercontent.com/MAIF/shapash/master/docs/_static/groups_features.gif" width="120" title="groups-features">
1.3.xShapash Report <br> DemoA standalone HTML report that constitutes a basis of an audit document.<img src="https://raw.githubusercontent.com/MAIF/shapash/master/docs/_static/report-icon.png" width="50" title="shapash-report">

🔥 Features

<p align="center"> <img align="left" src="https://github.com/MAIF/shapash/blob/master/docs/_static/shapash-grid-images-02.png?raw=true" width="28%"/> <img src="https://github.com/MAIF/shapash/blob/master/docs/_static/shapash-grid-images-06.png?raw=true" width="28%" /> <img align="right" src="https://github.com/MAIF/shapash/blob/master/docs/_static/shapash-grid-images-04.png?raw=true" width="28%" /> </p> <p align="center"> <img align="left" src="https://github.com/MAIF/shapash/blob/master/docs/_static/shapash-grid-images-01.png?raw=true" width="28%" /> <img src="https://github.com/MAIF/shapash/blob/master/docs/_static/shapash-resize.png?raw=true" width="18%" /> <img align="right" src="https://github.com/MAIF/shapash/blob/master/docs/_static/shapash-grid-images-13.png?raw=true" width="28%" /> </p> <p align="center"> <img align="left" src="https://github.com/MAIF/shapash/blob/master/docs/_static/shapash-grid-images-12.png?raw=true" width="33%" /> <img src="https://github.com/MAIF/shapash/blob/master/docs/_static/shapash-grid-images-03.png?raw=true" width="28%" /> <img align="right" src="https://github.com/MAIF/shapash/blob/master/docs/_static/shapash-grid-images-10.png?raw=true" width="25%" /> </p>

Shapash provides concise and clear local explanations, It allows each user, enabling users of any Data background to understand a local prediction of a supervised model through a summarized and explicit explanation

We believe that this report will offer valuable support for auditing models and data, leading to improved AI governance. Data Scientists can now provide anyone interested in their project with a document that captures various aspects of their work as the foundation for an audit report. This document can be easily shared among teams (internal audit, DPO, risk, compliance...).

<p align="center"> <img src="https://raw.githubusercontent.com/MAIF/shapash/master/docs/_static/shapash-report-demo.gif" width="800"> </p>

<a name="how_shapash_works"></a>

⚙️ How Shapash works

Shapash is an overlay package for libraries focused on model interpretability. It uses Shap or Lime backend to compute contributions. Shapash builds upon the various steps required to create a machine learning model, making the results more understandable.

<p align="center"> <img src="https://raw.githubusercontent.com/MAIF/shapash/master/docs/_static/shapash-diagram.png" width="700" title="diagram"> </p>

Shapash is suitable for Regression, Binary Classification or Multiclass problem. <br /> It is compatible with numerous models: Catboost, Xgboost, LightGBM, Sklearn Ensemble, Linear models, SVM. <br />

If your model is not in the list of compatible models, it is possible to provide Shapash with local contributions calculated with shap or another method. Here's an example of how to provide contributions to Shapash. An issue has been created to enhance this use case.

Shapash can use category-encoders object, sklearn ColumnTransformer or simply features dictionary. <br />

🛠 Installation

Shapash is intended to work with Python versions 3.9 to 3.12. Installation can be done with pip:

pip install shapash

In order to generate the Shapash Report some extra requirements are needed. You can install these using the following command :

pip install shapash[report]

If you encounter compatibility issues you may check the corresponding section in the Shapash documentation here.

🕐 Quickstart

The 4 steps to display results:

from shapash import SmartExplainer

xpl = SmartExplainer(
    model=regressor,
    features_dict=house_dict,  # Optional parameter
    preprocessing=encoder,  # Optional: compile step can use inverse_transform method
    postprocessing=postprocess,  # Optional: see tutorial postprocessing
)
xpl.compile(
    x=xtest,
    y_pred=y_pred,  # Optional: for your own prediction (by default: model.predict)
    y_target=yTest,  # Optional: allows to display True Values vs Predicted Values
    additional_data=xadditional,  # Optional: additional dataset of features for Webapp
    additional_features_dict=features_dict_additional,  # Optional: dict additional data
)
app = xpl.run_app()

Live Demo Shapash-Monitor

xpl.generate_report(
    output_file="path/to/output/report.html",
    project_info_file="path/to/project_info.yml",
    x_train=xtrain,
    y_train=ytrain,
    y_test=ytest,
    title_story="House prices report",
    title_description="""This document is a data science report of the kaggle house prices tutorial project.
        It was generated using the Shapash library.""",
    metrics=[{"name": "MSE", "path": "sklearn.metrics.mean_squared_error"}],
)

Report Example

predictor = xpl.to_smartpredictor()

See the tutorial part to know how to use the SmartPredictor object

📖 Tutorials

This github repository offers many tutorials to allow you to easily get started with Shapash.

<details><summary><b>Overview</b> </summary> </details> <details><summary><b>Charts and plots</b> </summary> </details> <details><summary><b>Different ways to use Encoders and Dictionaries</b> </summary> </details> <details><summary><b>Displaying data with postprocessing</b> </summary>

Using postprocessing parameter in compile method

</details> <details><summary><b>Using different backends</b> </summary> </details> <details><summary><b>Evaluating the quality of your explainability</b> </summary> </details> <details><summary><b>Generate a report of your project</b> </summary> </details> <details><summary><b>Analysing your model via Shapash WebApp</b> </summary> </details>

🤝 Contributors

<div align="left"> <div style="display: flex; align-items: flex-start;"> <a href="https://maif.github.io/projets.html" > <img align=middle src="https://github.com/MAIF/shapash/blob/master/docs/_static/logo_maif.png" width="18%"/> </a> <a href="https://www.quantmetry.com/" > <img align=middle src="https://github.com/MAIF/shapash/blob/master/docs/_static/logo_quantmetry.png" width="18%"/> </a> <img align=middle src="https://github.com/MAIF/shapash/blob/master/docs/_static/logo_societe_generale.png" width="18%" /> <img align=middle src="https://github.com/MAIF/shapash/blob/master/docs/_static/logo_groupe_vyv.png" width="18%" /> <a href="https://www.sixfoissept.com/en/" > <img align=middle src="https://github.com/MAIF/shapash/blob/master/docs/_static/logo_SixfoisSept.png" width="18%"/> </a> </div> </div>

🏆 Awards

<a href="https://raw.githubusercontent.com/MAIF/shapash/master/docs/_static/awards-argus-or.png"> <img align="left" src="https://raw.githubusercontent.com/MAIF/shapash/master/docs/_static/awards-argus-or.png" width="180" /> </a> <a href="https://www.kdnuggets.com/2021/04/shapash-machine-learning-models-understandable.html"> <img src="https://www.kdnuggets.com/images/tkb-2104-g.png?raw=true" width="65" /> </a>