Interpretable Machine Learning

Interpretable Machine Learning

Interpretable Machine Learning - Extracting human understandable insights from any Machine Learning model. A Guide for Making Black Box Models Explainable. Machine Learning doesn’t have to be a black box anymore. What use is a good model if we cannot explain the results to others. Interpretability is as important as creating a model.

In his book ‘Interpretable Machine Learning’, Christoph Molnar beautifully encapsulates the essence of ML interpretability through this example: Imagine you are a Data Scientist and in your free time you try to predict where your friends will go on vacation in the summer based on their facebook and twitter data you have. Now, if the predictions turn out to be accurate, your friends might be impressed and could consider you to be a magician who could see the future. If the predictions are wrong, it would still bring no harm to anyone except to your reputation of being a “Data Scientist”. Now let’s say it wasn’t a fun project and there were investments involved. Say, you wanted to invest in properties where your friends were likely to holiday. What would happen if the model’s predictions went awry?You would lose money. As long as the model is having no significant impact, it’s interpretability doesn’t matter so much but when there are implications involved based on a model’s prediction, be it financial or social, interpretability becomes relevant.

Explainable Machine Learning

Interpret means to explain or to present in understandable terms. In the context of ML systems, interpretability is the ability to explain or to present in understandable terms to a human[Finale Doshi-Velez]
Machine Learning models have been branded as ‘Black Boxes’ by many. This means that though we can get accurate predictions from them, we cannot clearly explain or identify the logic behind these predictions. But how do we go about extracting important insights from the models? What things are to be kept in mind and what features or tools will we need to achieve that? These are the important questions which come to mind when the issue of Model Explainability is raised.

Importance of interpretability

The question that some of the people often ask is why aren’t we just content with the results of the model and why are we so hell-bent on knowing why a particular decision was made? A lot of this has to do with the impact that a model might have in the real world. For models which are merely meant to recommend movies will have a far less impact than the ones created to predict the outcome of a drug.

Here is a big picture of explainable machine learning. In a way, we capture the world by collecting raw data and use that data to make further predictions. Essentially, Interpretability is just another layer on the model that helps humans to understand the process.

Some of the benefits that interpretability brings along are:

  • Reliability
  • Debugging
  • Informing feature engineering
  • Directing future data collection
  • Informing human decision-making
  • Building Trust
Model Explainability techniques

Theory only makes sense as long as we can put it into practice. In case you want a real hang of this topic, you can try the Machine Learning Explainability crash course from Kaggle. It has the right amount of theory and code to put the concepts into perspective and helps to apply model explainability concepts to practical, real-world problems.

Insights which can be extracted from the models

To interpret a model, we require the following insights :

  • Features in the model which are most important.
  • For any single prediction from a model, the effect of each feature in the data on that particular prediction.
  • Effect of each feature over a large number of possible predictions

Let’s discuss a few techniques which help in extracting the above insights from a model:

1. Permutation Importance

What features does a model think are important? Which features might have a greater impact on the model predictions than the others? This concept is called feature importance and Permutation Importance is a technique used widely for calculating feature importance. It helps us to see when our model produces counterintuitive results, and it helps to show the others when our model is working as we’d hope.

Permutation Importance works for many scikit-learn estimators. The idea is simple: Randomly permutate or shuffle a single column in the validation dataset leaving all the other columns intact. A feature is considered “important” if the model’s accuracy drops a lot and causes an increase in error. On the other hand, a feature is considered ‘unimportant’ if shuffling its values don’t affect the model’s accuracy.

Working

Consider a model that predicts whether a soccer team will have a “Man of the Game” winner or not based on certain parameters. The player who demonstrates the best play is awarded this title.

Permutation importance is calculated after a model has been fitted. So, let’s train and fit a RandomForestClassifier model denoted as my_model on the training data.

Permutation Importance is calculated using the ELI5 library. ELI5 is a Python library which allows to visualize and debug various Machine Learning models using unified API. It has built-in support for several ML frameworks and provides a way to explain black-box models.

Calculating and Displaying importance using the eli5 library:

(Here val_X,val_y denote the validation sets respectively)

import eli5
from eli5.sklearn import PermutationImportance

perm = PermutationImportance(my_model, random_state=1).fit(val_X, val_y)
eli5.show_weights(perm, feature_names = val_X.columns.tolist())

Interpretation

  • The features at the top are most important and at the bottom, the least. For this example, goals scored was the most important feature.
  • The number after the ± measures how performance varied from one-reshuffling to the next.
  • Some weights are negative. This is because in those cases predictions on the shuffled data were found to be more accurate than the real data.

Practice

And now, for the complete example and to test your understanding, go to the Kaggle page by clicking the link below:

Get Started Here

2. Partial Dependence Plots

The partial dependence plot (short PDP or PD plot) shows the marginal effect one or two features have on the predicted outcome of a machine learning model( J. H. Friedman 2001). PDPs show how a feature affects predictions. PDP can show the relationship between the target and the selected features via 1D or 2D plots.

Working

PDPs are also calculated after a model has been fit. In the soccer problem that we discussed above, there were a lot of features like passes made, shots taken, goals scored etc. We start by considering a single row. Say the row represents a team that had the ball 50% of the time, made 100 passes, took 10 shots and scored 1 goal.

We proceed by fitting our model and calculating the probability of a team having a player that won the “Man of the Game” which is our target variable. Next, we would choose a variable and continuously alter its value. For instance, we will calculate the outcome if the team scored 1 goal, 2 goals, 3 goals and so on. All these values are then plotted and we get a graph of predicted Outcomes vs Goals Scored.

The library to be used for plotting PDPs is called python partial dependence plot toolbox or simply PDPbox.

from matplotlib import pyplot as plt
from pdpbox import pdp, get_dataset, info_plots

# Create the data that we will plot
pdp_goals = pdp.pdp_isolate(model=my_model, dataset=val_X, model_features=feature_names, feature='Goal Scored')

# plot it
pdp.pdp_plot(pdp_goals, 'Goal Scored')
plt.show()

Interpretation

  • The Y-axis represents the change in prediction from what it would be predicted at the baseline or leftmost value.
  • Blue area denotes the confidence interval
  • For the ‘Goal Scored’ graph, we observe that scoring a goal increases the probability of getting a ‘Man of the game’ award but after a while saturation sets in.

We can also visualize the partial dependence of two features at once using 2D Partial plots.

Practise
Get Started Here

3. SHAP Values

SHAP which stands for SHapley Additive exPlanation, helps to break down a prediction to show the impact of each feature. It is based on Shapley values, a technique used in game theory to determine how much each player in a collaborative game has contributed to its success¹. Normally, getting the trade-off between accuracy and interpretability just right can be a difficult balancing act but SHAP values can deliver both.

Working

Again, going with the soccer example where we wanted to predict the probability of a team having a player that won the “Man of the Game”. SHAP values interpret the impact of having a certain value for a given feature in comparison to the prediction we’d make if that feature took some baseline value.

SHAP values are calculated using the Shap library which can be installed easily from PyPI or conda.

Shap values show how much a given feature changed our prediction (compared to if we made that prediction at some baseline value of that feature). Let’s say we wanted to know what was the prediction when the team scored 3 goals instead of some fixed baseline no. If we are able to answer this, we could perform the same steps for other features as follows:

sum(SHAP values for all features) = pred_for_team - pred_for_baseline_values

Hence the prediction can be decomposed into a graph like this:

Interpretation

The above explanation shows features each contributing to push the model output from the base value (the average model output over the training dataset we passed) to the model output. Features pushing the prediction higher are shown in red, those pushing the prediction lower are in blue

  • The base_value here is 0.4979 while our predicted value is 0.7.
  • Goal Scored = 2 has the biggest impact on increasing the prediction, while
  • ball possession feature has the biggest effect in decreasing the prediction.

Practice

SHAP values have a deeper theory than what I have explained here. make sure to through the link below to get a complete understanding.
Get Started Here

4. Advanced Uses of SHAP Values

Aggregating many SHAP values can provide even more detailed insights into the model.

  • SHAP Summary Plots

To get an overview of which features are most important for a model we can plot the SHAP values of every feature for every sample. The summary plot tells which features are most important, and also their range of effects over the dataset.

For every dot:

  • Vertical location shows what feature it is depicting
  • Color shows whether that feature was high or low for that row of the dataset
  • Horizontal location shows whether the effect of that value caused a higher or lower prediction.

The point in the upper left was for a team that scored few goals, reducing the prediction by 0.25.

  • SHAP Dependence Contribution Plots

While a SHAP summary plot gives a general overview of each feature, a SHAP dependence plot shows how the model output varies by a feature value. SHAP dependence contribution plots provide a similar insight to PDP’s, but they add a lot more detail.

The above Dependence Contribution plots suggest that having the ball increases a team’s chance of having their player win the award. But if they only score one goal, that trend reverses and the award judges may penalize them for having the ball so much if they score that little.

Practice

Get Started Here

Conclusion

Machine Learning doesn’t have to be a black box anymore. What use is a good model if we cannot explain the results to others. Interpretability is as important as creating a model. To achieve wider acceptance among the population, it is crucial that Machine learning systems are able to provide satisfactory explanations for their decisions. As Albert Einstein said,” If you can’t explain it simply, you don’t understand it well enough”.

5 Python Online Courses for Beginners

5 Python Online Courses for Beginners

If you are thinking to learn a new programming language then also Python is a good choice, particularly if you are looking to move towards a lucrative career path of Data Science and Machine learning which has lots of opportunities. In this article, I am going to share some of the best online courses to learn Python in 2020...

Python is an object-oriented, high-level programming language with integrated dynamic semantics primarily for web and app development. It is extremely attractive in the field of Rapid Application Development because it offers dynamic typing and dynamic binding options.

Python is relatively simple, so it's easy to learn since it requires a unique syntax that focuses on readability. Developers can read and translate Python code much easier than other languages. In turn, this reduces the cost of program maintenance and development because it allows teams to work collaboratively without significant language and experience barriers.

Additionally, Python supports the use of modules and packages, which means that programs can be designed in a modular style and code can be reused across a variety of projects. Once you've developed a module or package you need, it can be scaled for use in other projects, and it's easy to import or export these modules.

In recent years, Python has also become a default language for Data Science and Machine learning Projects and that's another reason why many experienced programmers are learning Python .

If you are thinking to learn a new programming language then also Python is a good choice, particularly if you are looking to move towards a lucrative career path of Data Science and Machine learning which has lots of opportunities. In this article, you will find free online courses in python programming, but not only will you find one, but you will also find 5 more courses on Python! I am going to share some of the best online courses to learn Python in 2020

They are high quality courses with more than 4 star rating (from 0 to 5 stars), that means if you are starting your career with the python programming language, these are the best courses that will take you step-by-step , to start and learn from scratch the fundamentals about this language that so professional and useful has been in recent years.

Top 5 Courses to Learn Python in 2020

1. Complete Python Bootcamp: Go from zero to hero in Python

This is one of the most popular course to learn Python on Udemy and more than 250,000 students have enrolled in it. That speaks volumes for the quality of the course.

This is a comprehensive but straight-forward course to learn the Python programming language on Udemy! and useful for all levels of programmers.

In this course, you will learn Python 3 in a practical manner. You will start by downloading and setting up Python on your machine and then slowly move on to different topics.

It's also a practical course where an instructor will show you live coding and explain what he does.

The course also comes with quizzes, notes and homework assignments as well as 3 major projects to create a Python project portfolio! which complements your learning.

2. 30 Days of Python | Unlock your Python Potential

In early 2016, Python passed Java as the #1 beginners language in the world. Why? It's because it's simple enough for beginners yet advanced enough for the pros.

You can not only write simple scripts to automate stuff but also create a complex program to handle trades. You can even use Python for it for IOT, Web Development, Big Data, Data Science, Machine learning and more.

This is a very practical course and useful not just for beginners but also for programmers who know other programming languages e.g. Java, C++ and want to learn Python.

In 30 days this course will teach you to write complex Python applications to scrape Data from nearly any website and Build your own Python applications for all types of automation. It's perfect for busy developers who learn by doing serious stuff.

3. Python for Beginners with Examples


This online Python course is taught by Ardit Sulce ,This Python course has everything you need to know to start coding in Python and not even that, by the end of the course you will know how to build complete programs and also build graphical user interfaces for your programs so you can impress your employer or your friends. This course will guide you step by step starting from the basics and always assuming you don't have previous programming experience or a computer science degree. In fact, most people who learn Python come from a vast variety of careers.

This course has all you need to get you started. After you take it you will be ready to go to the next level of specializing in any of the Python paths such as data science or web development. Python is one of the most needed skills nowadays. Sign up today!

4. Learn Python Programming Masterclass


This is another fantastic course to learn Python on Udemy. This course is taught by Tim Buchalka,I am a big fan of Tim Buchalka and have attended a couple of his courses.

This course is aimed at complete beginners who have never programmed before, as well as existing programmers who want to increase their career options by learning Python.

The fact is, Python is one of the most popular programming languages in the world – Huge companies like Google use it in mission critical applications like Google Search.

And Python is the number one language choice for machine learning, data science and artificial intelligence. To get those high paying jobs you need an expert knowledge of Python, and that’s what you will get from this course.

By the end of the course you’ll be able to apply in confidence for Python programming jobs. And yes, this applies even if you have never programmed before. With the right skills which you will learn in this course, you can become employable and valuable in the eyes of future employers.

5. The Python Bible™ | Everything You Need to Program in Python

This course was developed by Ziyad Yehia , a renowned instructor on Udemy. Currently, This course has nearly 78,000 students and excellent star ratings.

This is a project-based course and you will build 11 Projects int this Python Course.

If you enjoy hands-on learning while working on the project rather than learning individual concept then this course is for you.

This is a comprehensive, in-depth and meticulously prepared course and teaches you everything you need to know to program in Python. It delivers what is promised in the title, A-Z, it's all here!

Conclusion

That's all about the best courses to learn Python in depth. you can begin with these courses, don't need to buy all of them, just choose the one where you can connect with instructor.

These courses will give you a solid foundation and confidence to use Python in your project.

==========================================================

Thanks for reading

What NOT to Do in the Data Science Domains Industry

What NOT to Do in the Data Science Domains Industry

Data science is linked to numerous other modern buzzwords such as big data and machine learning, but data science itself is built from numerous domains, where you can get your expertise. These domains include the following: * Statistics *...

Data science is linked to numerous other modern buzzwords such as big data and machine learning, but data science itself is built from numerous domains, where you can get your expertise. These domains include the following:

  • Statistics
  • Visualization
  • Data mining
  • Machine learning
  • Pattern recognition
  • Data platform operations
  • Artificial intelligence
  • Programming
    Math and statistics
    Statistics and other math skills are essential in several phases of the data science project. Even in the beginning of data exploration, you'll be dividing the features of your data observations into categories:
  • Categorical
  • Numeric:
  • Discrete
  • Continuous
    Continuous values have an infinite number of possible values and use real numbers for the representation. In a nutshell, discrete variables are like points plotted on a chart, and a continuous variable can be plotted as a line.
    Another classification of the data is the measurement-level point of view. We can split data into two primary categories:
    Qualitative:
  • Nominal
  • Ordinal
  • Quantitative:
  • Interval
  • Ratio
    Nominal variables can't be ordered and only describe an attribute. An example would be the color of a product; this describes how the product looks, but you can't put any ordering scheme on the color saying that red is bigger than green, and so on. Ordinal variables describe the feature with a categorical value and provide an ordering system; for example Education—elementary, high school, university degree, and so on.

Visualizing the types of data
Visualizing and communicating data is incredibly important, especially with young companies that are making data-driven decisions for the first time, or companies where data scientists are viewed as people who help others make data-driven decisions. When it comes to communicating, this means describing your findings, or the way techniques work to audiences, both technical and non-technical. Different types of data have different ways of representation. When we talk about the categorical values, the ideal representation visuals would be these:

  • Bar charts
  • Pie charts
  • Pareto diagrams

Frequency distribution tables
A bar chart would visually represent the values stored in the frequency distribution tables. Each bar would represent one categorical value. A bar chart is also a baseline for a Pareto diagram, which includes the relative and cumulative frequency for the categorical values:

Bar chart representing the relative and cumulative frequency for the categorical values
If we'll add the cumulative frequency to the bar chart, we will have a Pareto diagram of the same data:

Pareto diagram representing the relative and cumulative frequency for the categorical values
Another very useful type of visualization for categorical data is the pie chart. Pie charts display the percentage of the total for each categorical value. In statistics, this is called the relative frequency. The relative frequency is the percentage of the total frequency of each category. This type of visual is commonly used for market-share

*Statistics *
A good understanding of statistics is vital for a data scientist. You should be familiar with statistical tests, distributions, maximum likelihood estimators, and so on. This will also be the case for machine learning, but one of the more important aspects of your statistics knowledge will be understanding when different techniques are (or aren't) a valid approach. Statistics is important for all types of companies, especially data-driven companies where stakeholders depend on your help to make decisions and design and evaluate experiments.

Machine learning
A very important part of data science is machine learning. Machine learning is the science of getting computers to act without being explicitly programmed. In the past decade, machine learning has given us self-driving cars, practical speech recognition, effective web search, and a vastly improved understanding of the human genome. Machine learning is so pervasive today that you probably use it dozens of times a day without knowing it.
**
Choosing the right algorithm**
When choosing the algorithm for machine learning, you have to consider numerous factors to properly choose the right algorithm for the task. It should not only be based on the predicted output: category, value, cluster, and so on, but also on numerous other factors, such as these:

  1. Training time
  2. Size of data and number of features you're processing
  3. Accuracy
  4. Linearity
  5. Number of possible parameters
    Training time can range from minutes to hours, depending not only on the algorithm but also on the number of features entering the model and the total amount of data that is being processed. However, a proper choice of algorithm can make the training time much shorter compared to the other. In general, regression models will reach the fastest training times, whereas neural network models will be on the other side of the training time length spectrum. Remember that developing a machine-learning model is iterative work. You will usually try several models and compare possible metrics. Based on the metrics captured, you'll fine-tune the models and run comparisons again on selected candidates and choose one model for operations. Even with more experience, you might not choose the right algorithm for your model at first, and you might be surprised that other algorithms can outperform the first chosen candidate, as shown:

Big data
Big data is another modern buzzword that you can find around the data management and analytics platforms. The big does not have to mean that the data volume is extremely large, although it usually is. learn more Data science online course
SQL Server and big data
Let's face reality. SQL Server is not a big-data system. However, there's a feature on the SQL Server that allows us to interact with other big-data systems, which are deployed in the enterprise. This is huge!
This allows us to use the traditional relational data on the SQL Server and combine it with the results from the big-data systems directly or even run the queries towards the big-data systems from the SQL Server. The answer to this problem is a technology called PolyBase:

Introduction to Face Processing with Computer Vision

Introduction to Face Processing with Computer Vision

In this Computer Vision tutorial, we’ll help you understand some of the Computer Vision, Face Processing with Computer Vision and Machine Learning techniques behind these applications. Then, we’ll use this knowledge to develop our own prototypes to tackle tasks such as face detection (e.g. digital cameras), recognition (e.g. Facebook Photos), classification (e.g. identifying emotions), manipulation (e.g. Snapchat filters), and more.

Ever wonder how Facebook’s facial recognition or Snapchat’s filters work? Faces are a fundamental piece of photography, and building applications around them has never been easier with open-source libraries and pre-trained models. In this talk, we’ll help you understand some of the computer vision and machine learning techniques behind these applications. Then, we’ll use this knowledge to develop our own prototypes to tackle tasks such as face detection (e.g. digital cameras), recognition (e.g. Facebook Photos), classification (e.g. identifying emotions), manipulation (e.g. Snapchat filters), and more.