Explain Me This : Machine Learning Interpretability : An Intro
Machine Learning. What more can I tell about a topic, that half the world has already written. So I wont.
Yes, I am.
Today, I shall be starting a new series called Explain Me This. My aim is basically to explain the Crux of a topic with Question and Examples that could be instantly tried out, clear basics and provide resources for you to figure the rest out yourself.
Detailed Information and research papers are just a search away, so our aim would be to understand comparatively niche topics in simple way with examples.
Enough boring you with words, lets get this rolling !
And for the first topic, we shall start with
MLI : Machine Learning Interpretability.
Now for detailed definitions and other theory, I shall be mentioning resources at the end. Initially though, we will keep it as layman as possible.
In order to do that, lets start asking and answering a few Questions and hopefully by end you shall be wondering how did time pass so quickly ?
Jokes apart, Lets get started.
Question 1 : What is MLI ?
In a single line, MLI is basically trying real hard to answer, why did the Model Predict what it did using various techniques.
The emphasis on trying is because, there is no straight answer. We cant say because of a single thing the result of prediction was 42. As models become more and more complex, from users perspective, we just enter an input from one end and output on other end. Fancy term for this is, Black box models
MLI tries to fix this, or atleast help out.
Question 2: Alright thats MLI, but why do i need this ?
Well, because in your local models, if a prediction is wrong all you lose is some reputation among friends and peers. But in serious ones, a biiiit more is at stake.
So 2 things start mattering,
- Why should I trust what this piece of code says
- If its wrong what factors made it choose the wrong answer
And MLI answers these questions, and in its process, helps build Trust over the model, and helps people take better decisions. So just as your models gives correct output, it should also give an idea to the user why.
Question 3: Okay maybe I’m sold on it, how do I try it for my models ?
Well it depends, the flow, of MLI is like this, you need to check in which stage are you currently.
Are you still collecting data, have you already prepped that data and its ready to be used to train the model, or you have an already trained model and you just want it to be interpreted.
If you are at the step 3, ready with the model and the data, then Bingo ! You can start interpreting.
Question 4: That’s all theory, show me code bro !
I know, I know what you are thinking, that’s childish, but there enough serious articles out there, at least lets have some fun here.
So as I said, there are various techniques :
- LIME
- DeepLIFT
- SHAPLEY
- SKATER
- AIX360
- RULEX
Just as an intro, I shall show you LIME.
PS : Detailed articles for every technique dropping from next week, a follow wont hurt xD
So, Lets start with LIME and Eli5 :
Here’s what we shall be doing, we will take IMDb movie reviews, create a classification model that basically predicts if its a positive or a negative review. Again, fancy word for this is sentiment analysis.
Done Till here, a we will now have black box model which takes input from one end, output from other.
Then, we shall use the above techniques, to make the model interpretable.
Understood the flow ? Lets write !
First of all, Lets read the dataset, and print it, should basically looks very simple 2 columns :
- Review
- Label ( 0 is negative and 1 is positive )
Then we build a basic model, using CountVectorizer, I wont go into details here, but I’ll share this notebook later and you can take a look at everything for yourself.
Finally, we import the eli5 library, pip install eli5 if not present, and write the following code.
What it does basically is :
- Create explainer object
- Fit the explainer model
- Call the requisite methods to show explainations
Here’s how the output looks for a positive review such as this one :
Definitely worth checking out.
Usually all you get from the model is, 0 or 1 … Now here’s what you get for this.
A colour coded sentence, individual breakdown of sentence as per importance of words.
Question 5: Cool, so some concept, some uses, some techniques, some examples, what else now ?
A clap would help to be honest.
But yeah now you have to take the call. If you think this is something that interests you, that attracts you then the world is your oyster. There are tons of use cases and lots to discover.
Here’s a number of resources I would recommend :
So thats it, from my side, all the kidding apart, I would really love some feedback about the article. Furthermore, detailed articles for every technique will be dropping, if interested please check those as well.
Have a great day, Cheers !