Package: shapash
🔍 OverviewShapash is a Python library designed tomake 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 aWebappthat simplifies the comprehension ofinteractions between the model's features, and allowsseamless navigation between local and global explainability. This Webapp enables Data Scientists to effortlessly understand their models andshare their results with both data scientists and non-data experts.Additionally, Shapash contributes to data science auditing bypresenting valuable informationabout any model and datain a comprehensive report.Shapash is suitable for Regression, Binary Classification and Multiclass problems. It iscompatible 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 foundhere.[!NOTE]
If you want to give us feedback :Feedback formShapash App Demo🌱 Documentation and resourcesReadthedocs:Video presentation for french speakersMedium:Understand your model with Shapash - Towards AIModel auditability - Towards DSGroup of features - Towards AIBuilding confidence on explainability - Towards DSPicking Examples to Understand Machine Learning ModelEnhancing Webapp Built-In Features for Comprehensive Machine Learning Model Interpretation🎉 What's new ?VersionNew FeatureDescriptionTutorial2.3.xAdditional dataset columnsNew demoArticleIn Webapp: Target and error columns added to dataset and possibility to add features outside the model for more filtering options2.3.xIdentity cardNew demoArticleIn Webapp: New identity card to summarize the information of the selected sample2.2.xPicking samplesArticleNew tab in the webapp for picking samples. The graph represents the "True Values Vs Predicted Values"2.2.xDataset FilterNew tab in the webapp to filter data. And several improvements in the webapp: subtitles, labels, screen adjustments2.0.xRefactoring ShapashRefactoring attributes of compile methods and init. Refactoring implementation for new backends1.7.xVariabilize ColorsGiving possibility to have your own colour palette for outputs adapted to your design1.6.xExplainability Quality MetricsArticleTo help increase confidence in explainability methods, you can evaluate the relevance of your explainability using 3 metrics:Stability,ConsistencyandCompacity1.4.xGroups of featuresDemoYou can now regroup features that share common properties together.This option can be useful if your model has a lot of features.1.3.xShapash ReportDemoA standalone HTML report that constitutes a basis of an audit document.🔥 FeaturesDisplay clear and understandable results: plots and outputs useexplicit labelsfor each feature and its valuesAllow Data Scientists to quickly understand their models using awebappto easily navigate between global and local explainability, and understand how the different features contribute:Live Demo Shapash-MonitorSummarize and exportlocal explanationShapashprovides 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 explanationEvaluatethe quality of your explainability with various metricsEffortlessly share and discuss results with non-Data usersSelect subsets for in-depth analysis of explainability by filtering based on explanatory and additional features, as well as correct or wrong predictions.Picking Examples to Understand Machine Learning ModelDeploy interpretability part of your project: From model training to deployment (API or Batch Mode)Contribute to theauditability of your modelby generating astandalone HTML reportof your projects.Report ExampleWe 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 witha 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...).⚙️ How Shapash worksShapashis an overlay package for libraries focused on model interpretability. It uses Shap or Lime backend
to compute contributions.Shapashbuilds upon the various steps required to create a machine learning model, making the results more understandable.Shapashis suitable for Regression, Binary Classification or Multiclass problem.It is compatible with numerous models:Catboost,Xgboost,LightGBM,Sklearn Ensemble,Linear models,SVM.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'san example of how to provide contributions to Shapash. Anissuehas been created to enhance this use case.Shapash can use category-encoders object, sklearn ColumnTransformer or simply features dictionary.Category_encoder:OneHotEncoder,OrdinalEncoder,BaseNEncoder,BinaryEncoder,TargetEncoderSklearn ColumnTransformer:OneHotEncoder,OrdinalEncoder,StandardScaler,QuantileTransformer,PowerTransformer🛠 InstallationShapash is intended to work with Python versions 3.8 to 3.11. Installation can be done with pip:pipinstallshapashIn order to generate the Shapash Report some extra requirements are needed.
You can install these using the following command :pipinstallshapash[report]If you encountercompatibility issuesyou may check the corresponding section in the Shapash documentationhere.🕐 QuickstartThe 4 steps to display results:Step 1: Declare SmartExplainer ObjectThere 1 mandatory parameter in compile method: Model
You can declare features dict here to specify the labels to displayfromshapashimportSmartExplainerxpl=SmartExplainer(model=regressor,features_dict=house_dict,# Optional parameterpreprocessing=encoder,# Optional: compile step can use inverse_transform methodpostprocessing=postprocess,# Optional: see tutorial postprocessing)Step 2: Compile  Dataset, ...There 1 mandatory parameter in compile method: Datasetxpl.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 Valuesadditional_data=xadditional,# Optional: additional dataset of features for Webappadditional_features_dict=features_dict_additional,# Optional: dict additional data)Step 3: Display outputThere are several outputs and plots available. for example, you can launch the web app:app=xpl.run_app()Live Demo Shapash-MonitorStep 4: Generate the Shapash ReportThis step allows to generate a standalone html report of your project using the different splits
of your dataset and also the metrics you used: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 ExampleStep 5: From training to deployment : SmartPredictor ObjectShapash provides a SmartPredictor object to deploy the summary of local explanation for the operational needs.
It is an object dedicated to deployment, lighter than SmartExplainer with additional consistency checks.
SmartPredictor can be used with an API or in batch mode. It provides predictions, detailed or summarized local
explainability using appropriate wording.predictor=xpl.to_smartpredictor()See the tutorial part to know how to use the SmartPredictor object📖  TutorialsThis github repository offers many tutorials to allow you to easily get started with Shapash.OverviewLaunch the webapp with a concrete use caseJupyter Overviews - The main outputs and methods available with the SmartExplainer objectShapash in production: From model training to deployment (API or Batch Mode)Use groups of featuresDeploy local explainability in production with SmartPredictorCharts and plotsShapashFeatures ImportanceContribution plot to understand how one feature affects a predictionSummarize, display and export local contribution using filter and local_plot methodContributions Comparing plot to understand why predictions on several individuals are differentVisualize interactions between couple of variablesDisplay True Values Vs Predicted ValuesCustomize colors in Webapp, plots and reportDifferent ways to use Encoders and DictionariesUse Category_Encoder & inverse transformationUse ColumnTransformersUse Simple Python DictionnariesDisplaying data with postprocessingUsing postprocessing parameter in compile methodUsing different backendsCompute Shapley Contributions usingShapUseLimeto compute local explanation, Summarize-it withShapashCompile faster Lime and consistency of contributionsUseFastTreeSHAPor add contributions from another backendUse Class Shapash BackendEvaluating the quality of your explainabilityBuilding confidence on explainability methods usingStability,ConsistencyandCompacitymetricsGenerate a report of your projectGenerate a standalone HTML report of your project with generate_reportAnalysing your model via Shapash WebAppAdd features outside of the model for more exploration options🤝 Contributors🏆 Awards