Machine Learning Model Interpretability
|Building a ML Pipeline : Part 5
Because sometimes the evaluation metrics wont be enough..
Until unless inherently interpretable models such as Linear Regression, Logistic Regression, GLM, GAM, Decision Tree etc. are used, interpreting a Black Box Model becomes a necessity for the built model to go into production.
This is the Fifth and the last article in the series Building a ML Pipeline, in continuation to below mentioned articles:
Part 1 : Building Blocks of a ML Pipeline
Part 2 : Reading the Data to Feature Engineering
Part 4 : Machine Learning Pipeline
1) Intro
Being the fifth and final article in the Building a ML Pipeline series, i would highly recommend you to go through the prior articles in the series, you can find the links above.
“..The Information Commissioner’s Office (ICO) is putting forward a regulation that businesses and other organizations are required to explain decisions made by artificial intelligence (AI) or face multimillion-dollar fines if unable to…” — techhq.com, Dec 2019
As rise of Machine Learning/AI has propagated it to penetrate into various aspects of the public life it has also amplified the need for regulations put forth by the governments on the same..
“..In February 2019 Polish government added an amendment to a banking law that gives a customer a right to receive an explanation in case of a negative credit decision…” — kdnuggets.com
And this has lead to various advances in Model Interpretability , a much under appreciated realm of the Machine learning universe. From as basic as Feature Importance to LIME, SHAP etc. Google launched Explainable AI in late 2019.
This article deals with aspect of model interpretability i.e given a Black Box Model, which has been selected as a solution for a specific problem how do you go about making sense of the intricacies that go inside it?
Are you happy with the predictions that your model made, or do you want to know the Why the predictions were made.
If you have gone through the prior articles in this series, then the model that we selected to predict the price at auction an was RandomForestRegressor. A tree based ensemble Bagging model.
If the models were to be utilised by the bidder or the auctioneer to predict the price of a particular model at which it will be auctioned, then that becomes a high stake problem both for bidders and for the auctioneer as it involves money. With high stakes stems out the insect of human curiosity and start asking “Which features does this model find the most useful?” or “Why did it price that model at $500,000 when almost similar model was auctioned for $100,000??”.
There are two different set of model explainability tools at your disposal,
- Model Dependent Explanation : As the name suggests, those explainability techniques which are available for a certain algorithm/model alone.
- Model Agnostic Explanation : Techniques which can be leveraged on any Machine Learning model, irrespective of the model that has been used.
which explain three different type of Explainability :
- Global : Explaining the entire model as a whole.
- Local : Explaining individual predictions.
- Per Feature : How does a feature behave w.r.t to the model predictions or the actual target variable.
Since this is in continuation to the prior article, assume that the trained RandomForestRegressor is present against the variablemodel
in the environment.
Method 1 : Correlation @ Per Feature
Correlation is a measure of how two variable are associated with each other (Positive or Negative Corrrelation) and by how much (between -1 →+1). It is a Bi-Variate technique to measure the strength between two variables.
e.g Does the Advertising effect the Retail Sales? And if so by how much?
Correlations just tries to answer the question that wether a target variable Retail Sales is dependent on a feature Advertising or not and if it is then by how much and in what direction i.e Positively or Negatively?
There are different types of Correlations that can be employed to measure the association of target variable to a features, i have covered this topic in another article.
Method 2 : PDP & ICE Plots @ Per Feature
PDP : Partial Dependence Plot shows the marginal effect one or two features have on the predicted outcome of a machine learning model.
ICE : Individual Conditional Expectation Plot gauges on how the predictions will change with the change in the features value.
Given a dataset D with n observations and p predictor variables and y as response variable.
For the variable pᵢ of interest ,
- STEP 1 : For each instance in the dataset D, keeping other features constant, permute through all the values of pᵢ for a single instance and make predictions[So if pᵢ has 100 unique values, and there are 1000 datapoints, the new dataset becomes 100*1000 in rows].
- STEP 2 : Now, for predictions group-by the unique values of pᵢ(X axis in PDP Plot) and take the mean per group of unique values of pᵢ(Y axis in PDP Plot).
Negate the STEP 2 in pdp calculation, and then the plot generated would be representing each instance in stead of the averaged effect — Individual Conditional Expectation (ICE) Plot.
This article here has a much simpler explanation of how to interpret PDP and ICE plots.
Method 3: LIME @ Local
Local Interpretable Model-agnostic Explanations : In Layman terms, what LIME does is given any model, be a complex one or a fairly simple one, it will try an answer the question - Why did this model predict a particular ŷ for a particular X?.
Suppose we wanted to know why the highlighted red dot prediction was made. So LIME will sample data-points near that highlighted red data-point and fit a fairly simple model for eg Linear Regression or as in this case Logistic Regression and then see the weights across the feature space and the feature weights of this locally trained model will become our interpretation!
Method 4: ELI5 @ Global & Local
“Explain Like I’m 5” -is a package that incorporates various methods and techniques around model explainability.
ELI5 can be leveraged to find explanation for the entire model (Global) or for each prediction (Local). ELI5 also provides a neat feature for calculating PermutationImportance , I have discussed about that in Method 7.
Method 5: SHAP @ Global & Local
SHapely Additive exPlanations Values, motivated by the work done by Lloyd Shapley(1953) in Game Theory. The Shapley value is the average marginal contribution of a feature value across all possible coalitions.
Method 6: Tree Visualisation @ Global
Since random forest is an ensemble method i.e it consists of multiple estimators (Decision Trees) which then at last contribute to the final prediction. We can not see all the trees at once but what we can do randomly pick from those trees and see how the tree is being built which can give some intuition about which features are coming out to be important and what are the good dissection value among each.
Instead of just visualising just the split points at each node and the number of samples traversing through, it would be more helpful to see the data traversing through that leaf and the split point at which each further split would be made.. dtreeviz is just the library for that (Authors Talk).
Method 7: Feature Importance@ Global
As the coefficients for Linear Regression model shed light on how important a feature might be for the target variable. Similarly RandomForestRegressor has something called as Feature Importance for the trained model.
There are multiple ways in which you can calculate Feature Importance of an Ensemble Based Tree model :
You can find a detailed explanations of these three methods in this article here.
To understand how default RF Feature Importance are calculated internally, look at this SO Conversation for a better understanding.
“..It’s also worth pointing out that feature importances should only be trusted with a strong model. If your model does not generalize accurately, feature importances are worthless. If your model is weak, you will notice that the feature importances fluctuate dramatically from run to run..” — Article
Phew! Quite frankly writing this was more intensive than i thought it would be.
As always, I welcome any feedback, you can put that in comments below or reach out to me on LinkedIn, would love to connect.
See you next time..!Au Revoir!🙋🏽♂️