Interpreting Machine Learning Model | by Marcos Silva | Towards Data Science

In this series of 6 posts we will leave the basics of prediction aside and look at a more handcrafted aspect of data science and machine learning, such as interpreting, gaining insights, and understanding what goes on within algorithms. It is not a trivial matter and is far from exhausted.In this series of posts we’ll start with the simplest statistical models and how we model even the most sophisticated ensemble and deep learning models trying to figure out the whys of a prediction.
The initial suggestion for the content of this series will be as follows:
Part 0— What is the scope of data sciencePart 1 — Introduction to Interpreting ML(This Post)Part 2 — Interpreting models of high bias and low variance. Part 3 — Interpreting models of low bias and high variance.Part 4 — Is it possible to solve the trade-off between bias and variance?Part 5 — Local Methods of Interpretability.Part 6 — Global Methods of Interpretability.
To understand how to interpret machine learning algorithms, let’s first understand what a machine learning algorithm is.
Quite generally, for us Machine Learning Algorithms (hereinafter only ML) are a paradigm shift from “traditional programming” where we need to explicitly pass all heuristics to a new concept, where instead of writing every action that the algorithm must perform, We just go through several examples and let ML learn what are the “best” (lowest cost) decisions.
That is, algorithms that receive inputs and can transform outputs without being explicitly programmable, for us, will be ML algorithms. Interpreting ML algorithms is understood how they can transform inputs into outputs.
If ML is just a way of mapping inputs to outputs in a (sometimes) quite clever way, it seems like a good idea to understand how it can do this magic, right?
An example: Bank fraud detection algorithms.We map a behavior, collect the data, train a model and you’re done! We have a very clever way of detecting future fraud. And now? What is this algorithm doing? If just by curiosity it would no longer make sense to understand it here are some more practical reasons:
What did this particular customer do to be considered a fraudster?
What kind of fraud is he committing?
Is my algorithm being biased?
Does my algorithm have any leakage?
If the customer wants to know why their purchase was denied, will I say it was an algorithm I don’t understand?
And does the manager want to understand how the behavior of model fraudsters is changing over time?
And if instead of simply predicting, we’re interested in fixing security holes to guard against future fraud, how will I know which levers are correct?
Even in this very simple example, we have identified several good reasons for understanding what the algorithm does inside.
If you are still not convinced of the importance, there is a very strong trend starting in Europe where companies are already forced to explain the reasons for a decision such as refusing credit, insurance, job vacancy, etc. makes a lot of sense, so it should not be long before this is a daily concern when using predictive models.
There are hundreds of posts talking about the trade-off between bias and variance and the goal here is not to re-explain all the concepts, just to use them as language for the next posts to come. So without theoretical formalism, we can divide the prediction error (y-yhat) of any model into 3 distinct components.
y_real - y_hat = Error = Random Part + Bias + Variance
Random Part: We live in a stochastic world and not in a deterministic world as positivists thought in the late nineteenth century. So even the simplest, most obvious models still have randomness. Even if your model is perfect, it will not reach Error = 0, only if it is a purely deterministic problem. Some problems are “more stochastic” than others. For example, a model that predicts the orbit of a planet has a much smaller random component than a model that predicts fraud. The random part can be considered as a horizontal line in the figure above as it does not depend on complexity.Variance: Interpretation of variance, for us, will be a kind of “volatility” of predictions. Small changes in X cause large changes in y? -> Variance. Usually the variance error stretch is considered to be the difference between the predicted training and test results, but this is an effect and not a cause. The variance increases with increasing model complexity.Bias: This is the most important kind of mistake for us. Bias has several interpretations in different contexts. Here, bias means the simplifications of our model, the assumptions we have to assume for the model to work. Simpler models, by definition, are more skewed models with stronger prerequisites. The bias decreases with increasing complexity.
Random Part: We live in a stochastic world and not in a deterministic world as positivists thought in the late nineteenth century. So even the simplest, most obvious models still have randomness. Even if your model is perfect, it will not reach Error = 0, only if it is a purely deterministic problem. Some problems are “more stochastic” than others. For example, a model that predicts the orbit of a planet has a much smaller random component than a model that predicts fraud. The random part can be considered as a horizontal line in the figure above as it does not depend on complexity.
Variance: Interpretation of variance, for us, will be a kind of “volatility” of predictions. Small changes in X cause large changes in y? -> Variance. Usually the variance error stretch is considered to be the difference between the predicted training and test results, but this is an effect and not a cause. The variance increases with increasing model complexity.
Bias: This is the most important kind of mistake for us. Bias has several interpretations in different contexts. Here, bias means the simplifications of our model, the assumptions we have to assume for the model to work. Simpler models, by definition, are more skewed models with stronger prerequisites. The bias decreases with increasing complexity.
We discussed in the previous post that Machine Learning may differ from Statistics because the former is concerned with inference, causality, exogeneity, etc. and the latter is concerned almost exclusively with improving predictions. So we can take the same function, for example a logistic regression and statistical analysis, which would interpret if betas are significant, if the waste has a normal distribution or Machine Learning analysis, how is the relationship between Precision and Recall, what is the AUC of the model, etc.
So, because statistics are interested in understanding data, you create models for it, these models need to be highly interpretable! For them to be interpretable, the models must be Simple! But if the models are simple, as we have seen, they are highly skewed.
ML models have the exact opposite, as we are not originally concerned with interpreting them, they are very biased, in our concept, they have few prerequisites, and the cost of this is lack of interpretability, this series of posts try to bring these two worlds together. High metrics with high interpretability.
A simple example is linear regression, one of the oldest and simplest algorithms, highly interpretable, very low variance (we hardly need to separate data in test training), but highly biased. As biases here are the simplifications for the model to work well, below some of these pre-Requirements to use this approach:
Input variables need to be exogenous, so do not understand interaction between variables;The influences between X and y need to be constant (hence the linear name);The y distribution needs to be “well-behaved”.
Input variables need to be exogenous, so do not understand interaction between variables;
The influences between X and y need to be constant (hence the linear name);
The y distribution needs to be “well-behaved”.
We’ll look at these and other prerequisites as well as how to interpret them in the next post.
To put it all together, let’s use a new term to describe this new way of separating / classifying ML algorithms. On the one hand we have the most traditional algorithms, born in statistics and econometrics, with some prerequisites to work and highly interpretable, there would be no modern science without them, and their interpretation is that of the scientific character for data science, are the “White Box” algorithms.
And at the other extreme, we have those ML algorithms that we know work very well, because their metrics are great, they can work with millions of variables at the same time, they can make representations of complex vector spaces in smaller dimensions, with very few prerequisites (low bias),can even generate images and text, at the cost that we do not have so much control over what he does inside, we call these algorithms “Black Box”.
In the next posts our goal will be to combine the good side of these two extremes, high interpretability with high predictive ability.
Next post: Part 2 — Interpreting high bias and low variance models.
LinkedIn; GitHub; Playlist; Version pt-br;