Home > Article > Technology peripherals > Another machine learning model interpretation artifact: Shapash
Model interpretability and understandability have been the focus of many research papers and open source projects . And many projects are staffed with data experts and trained professionals.
Shapash works with most sklearn, lightgbm, xgboost, catboost models and can be used for classification and regression tasks. It utilizes the Shap backend to calculate the local contribution of features, however, this can be replaced by some other strategy for calculating local contribution. Data scientists can leverage the Shapash interpreter to investigate and troubleshoot their models, or deploy it to provide visualizations of each inference. And it can also be used to make web applications that can bring huge value to end customers and entrepreneurs.
shabash library
Plotting and output use every Tags for each component and its pattern:
Data scientists can easily explore between global and local neighborhoods by using a web application to quickly understand their model and understand how various key points work:
shapash library webapp
Shapash presents a short and clear explanation. It allows every customer, no matter what their background, to understand a clear explanation of the hosting model because the Shapash features are summarized and clearly explained.
The complete data report can be viewed here: https://shapash-demo.ossbymaif.fr/
Some functions of Shapash are as follows:
1. Machine learning model: It is suitable for classification (binary or multi-class problems) and regression problems. It supports multiple models such as Catboost, Xgboost, LightGBM, Sklearn Ensemble, linear models, and SVM.
2. Feature encoding: It supports a large number of encoding techniques to process categorical features in our data set, such as one-hot encoding, ordinal encoding, Base N encoding, target encoding or binary encoding, etc.
3.SklearnColumnTransformer: OneHotEncoder, OrdinalEncoder, StandardScaler, QuantileTransformer or PowerTransformer
4.Visualization: Provides a set of visual effects to easily explain your results and display understandable and clear results.
5. It is compatible with Lime and Shap. It uses the Shap backend to display results in just a few lines of code.
6. It provides many options for parameters to obtain results concisely.
7.Shapash is easy to install and use: It provides a SmartExplainer class to understand your model and summarize and clarify it with simple syntax.
8. Deployment: Investigation and deployment (via API or batch mode) of operational usage is important. Easily create web applications to navigate from global to local.
9. High versatility: To display the results, many arguments are required. But the more you do to clean and archive your data, the clearer the results will be for your end customers.
Shapash is a Python library that makes machine learning easy to understand and interpret. Data enthusiasts can easily understand and share their models. Shapash uses Lime and Shap as a backend to display results in just a few lines of code. Shapash relies on various important advances in building machine learning models to make the results reasonable. The following figure shows the workflow of the shapash package:
How Shapash works
You can install Shapash using the following code:
<span style="color: rgb(89, 89, 89); margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0);">pip</span> <span style="color: rgb(89, 89, 89); margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0);">install</span> <span style="color: rgb(89, 89, 89); margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0);">shapash</span>
For Jupyter Notebook: If you are using jupyter notebook and want to view inline graphs, then you Another command is required:
<span style="color: rgb(89, 89, 89); margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0);">pip</span> <span style="color: rgb(89, 89, 89); margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0);">install</span> <span style="color: rgb(89, 89, 89); margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0);">ipywidgets</span>
Here we will explore Shapash using the dataset House Price Prediction. This is a regression problem and we have to predict house prices. First we analyze the dataset, including univariate and bivariate analyses, then model interpretability using feature importance, feature contribution, local and comparison plots, then model performance, and finally WebApp.
Univariate Analysis
Use You can view the image below to understand the element named First Floor Square Feet. We can see a table that shows various statistics for our training and test datasets, such as mean, maximum, minimum, standard deviation, median, and more. In the figure on the right you can see the distribution plots of the training and test data sets. Shapash also mentions whether our features are categorical or numeric and it also provides a drop-down option where all features are available.
Univariate analysis
For categorical features, the training and test datasets show non-duplicate and missing values. On the right, a bar chart is shown showing the percentage of the corresponding category in each feature.
Categories in Features
Goal Analysis
You can also see the target named Sales Price Detailed analysis of variables. On the left, all statistics such as count, mean, standard deviation, minimum, maximum, median, etc. are shown for training and prediction datasets. On the right, the distributions of the training and prediction datasets are shown.
Objective analysis
Multivariate analysis
We discussed univariate analysis in detail above. In this section we will look at multivariate analysis. The following figure shows the correlation matrix for the first 20 features of the training and test datasets. The correlation scale is also shown based on different colors. This is how we use Shapash to visualize relationships between features.
Multivariate Analysis
Feature Importance Plot
Passed Using this library we can see the importance of this feature. Feature importance is a method of finding the importance of input features in predicting output values. The following figure shows the feature importance curve:
Feature Importance Plot
Feature Contribution Plot
These Curves help us answer questions like how does a feature affect my prediction, whether its contribution is positive or negative, etc. This diagram completes the importance of the interpretability of the model, the overall consistency of the model makes it more likely to understand the impact of features on the model.
We can see the contribution plots of numerical and categorical features.
For numerical features
Contribution graph
For categorical features
For classification features
Partial map
We can draw a local map. The following figure shows a partial diagram:
Partial diagram
Comparison diagram
We can draw a comparison diagram. The following image shows the comparison graph:
Comparison graph
After data analysis, we are training the machine learning model. The image below shows the output of our prediction. On the left, statistics such as count, minimum, maximum, median, standard deviation, etc. are shown for the true and predicted values. On the right, the distribution of predicted and actual values is shown.
Model Performance
After model training, we can also build a WebApp. This web app shows a complete dashboard of our data, including what we've covered so far. The image below shows the dashboard.
WebApp
Project address: https://github.com/MAIF/shapash
This article briefly introduces the basic functions and drawing display of shapash. I believe everyone has a certain understanding of this python library.
The above is the detailed content of Another machine learning model interpretation artifact: Shapash. For more information, please follow other related articles on the PHP Chinese website!