<![CDATA[Amaljith]]>https://amaljith.me/https://amaljith.me/favicon.pngAmaljithhttps://amaljith.me/Jamify 1.0Mon, 14 Oct 2024 17:31:46 GMT60<![CDATA[Causal Machine Learning - Part 2]]>https://amaljith.me/causal-machine-learning-part-2/Ghost__Post__63aaf0f3bdc6867fe35525cbTue, 27 Dec 2022 13:21:50 GMT

This post is the second post of the series on Causal Machine Learning. In the last blog post i have given a brief introduction on Causal Machine Learning. In this we will uncover the WHY !. This blog post is based on the work of Judea Pearl. I will discuss how naive statistics can fail (Spurious Correlations , Simpson Paradox & Asymmetry In Causal Inference). As always i will try to keep the things as simple as possible. So stay with me , Enjoy reading !

How (Naive) Statistics Can Fail Us !

1. Spurious Correlations

Correllation Is Not Causation !!!

I know you are bored of this like every other, hearing this oft-repeated saying “correlation does not imply causation”. I will formally illustrate why this is in this post.

In the website, “Spurious Correlations” by Tyler Vigen, we can explore a wide variety of statistical correlations (that are due to chance) with no causal implications. One of them is listed below.

Causal Machine Learning - Part 2

We clearly know No of people who drowned while in a swimming pool has nothing to do with the power generated by US nuclear power plants !!. You can find more interesting “Spurious Correlations” from Tyler Vigen website.

2. Simpson's Paradox

Spurious correlations are well-known in statistics, so it’s easy (Somewhat !) to be on the lookout for it. Lets see a little known paradox in statistics.

Simpson's paradox is a phenomenon in probability and statistics in which a trend appears in several groups of data but disappears or reverses when the groups are combined. Lets look at an example of Simpson's paradox from Wikipedia itself.

Causal Machine Learning - Part 2

In both 1995 and 1996, Justice had a higher batting average (in bold type) than Jeter did. However, when the two baseball seasons are combined, Jeter shows a higher batting average than Justice.

Same data give contradictory conclusions depending on how you look at them! .

Simpson’s paradox highlights that how you look at your data matters. So the question becomes, how do we partition data? Although there is no standard method in statistics for this, causal inference provides a formalism to handle this problem. It all boils down to causal effects, which quantify the impact a variable has on another variable after adjusting for the appropriate confounders.

Let us look at an example from “The Book of Why: The New Science of Cause and Effect” by Judea Pearl , and a post the legend himself posted in his twitter handle.

Consider the below study that measures weekly exercise and cholesterol in various age groups. When we plot exercise on the X-axis and cholesterol on the Y-axis and segregate by age, as in left side of Fig , we see that there is a general trend downward in each group; the more young people exercise, the lower their cholesterol is, and the same applies for middle-aged people and the elderly. If, however, we use the same scatter plot, but we don’t segregate by gender (as in right side of Fig), we see a general trend upward; the more a person exercises, the higher their cholesterol is.

Causal Machine Learning - Part 2

Excercise appears to be beneficial in each age group but harmful in the population as a whole !!!

To resolve this problem, we once again turn to the story behind the data. If we know that older people, who are more likely to exercise  are also more likely to have high cholesterol regardless of exercise, then the reversal is easily explained, and easily resolved. Age is a common cause of both treatment (exercise) and outcome (cholesterol). So we should look at the age-segregated data in order to compare same-age people and thereby eliminate the possibility that the high exercisers in each group we examine are more likely to have high cholesterol due to their age, and not due to exercising.

However, please do not get confused , segregated data does not always give the correct answer.

Lets look at another example from the Causal Inference In Statistics book by Pearl.

In the classical example used by Simpson (1951), a group of sick patients are given the option to try a new drug. Among those who took the drug, a lower percentage recovered than among those who did not. However, when we partition by gender, we see that more men taking the drug recover than do men are not taking the drug, and more women taking the drug recover than do women are not taking the drug!

Causal Machine Learning - Part 2

In other words, the drug appears to help men and women, but hurt the general population. It seems nonsensical, or even impossible—which is why, of course, it is considered a paradox. Some people find it hard to believe that numbers could even be combined in such a way.

The data seem to say that if we know the patient’s gender male or female we can prescribe the drug, but if the gender is unknown we should not! Obviously, that conclusion is ridiculous. If the drug helps men and women, it must help anyone; our lack of knowledge of the patient’s gender cannot make the drug harmful.

Given the results of this study, then, should a doctor prescribe the drug for a woman? A man? A patient of unknown gender? Or consider a policy maker who is evaluating the drug’s overall effectiveness on the population. Should he/she use the recovery rate for the general population? Or should he/she use the recovery rates for the gendered sub-populations?

The answer is nowhere to be found in simple statistics.

In order to decide whether the drug will harm or help a patient, we first have to understand the story behind the data , the causal mechanism that led to, or generated, the results we see. For instance, suppose we knew an additional fact: Estrogen has a negative effect on recovery, so women are less likely to recover than men, regardless of the drug. In addition, as we can see from the data, women are significantly more likely to take the drug than men are. So, the reason the drug appears to be harmful overall is that, if we select a drug user at random, that person is more likely to be a woman and hence less likely to recover than a random person who does not take the drug. Put differently, being a woman is a common cause of both drug taking and failure to recover. Therefore, to assess the effectiveness, we need to compare subjects of the same gender, thereby ensuring that any difference in recovery rates between those who take the drug and those who do not is not ascribable to estrogen.

In fact, as statistics textbooks have traditionally (and correctly) warned students, correlation is not causation, so there is no statistical method that can determine the causal story from the data alone. Consequently, there is no statistical method that can aid in our decision.

3. Symmetry

The problems with traditional statistics when thinking about causality stems from a fundamental property of algebra, symmetry . The left-hand side of an equation equals the right-hand side (that’s the point of algebra). The equal sign implies symmetry. However, causality is fundamentally asymmetric i.e. causes lead to effects and not the other way around.

This distinction further implies that causal relations cannot be expressed in the language of probability and, hence, that any mathematical approach to causal analysis must acquire new notation – probability calculus is insufficient. To illustrate, the syntax of probability calculus does not permit us to express the simple fact that “symptoms do not cause diseases,” let alone draw mathematical conclusions from such facts. All we can say is that two events are dependent—meaning that if we find one, we can expect to encounter the other, but we cannot distinguish statistical dependence, quantified by the conditional probability P(disease|symptom) from causal dependence, for which we have no expression in standard probability calculus.

Let’s look at a simple example taken from Judea Pearl book itself . Suppose we model the relationship between a disease and the symptoms it produces, with the expression below. Y represents the severity of the symptoms, X the severity of the disease, m is the connection between the two, and b represents all other factors.

Causal Machine Learning - Part 2

Using the rules of algebra we can invert the equation above to get the following expression.

Causal Machine Learning - Part 2

Here’s the problem, if we interpret the first equation as diseases cause symptoms, then we have to interpret the second equation as symptoms cause diseases! Which is of course not true.

Note : Linear relations are used here for illustration purposes only; they do not represent typical disease-symptom relations but illustrate the historical development of path analysis.

Why Association (Correlation) Is Not Causation ?

Before moving to the next set of blog posts , I should precisely define what a correlation is. I know you all are bored with listening this oft-repeated saying "Correlation is not causation" , so am i. So lets sort this out before moving to anything else!

Before moving ahead lets clarify one more thing : “Correlation” is often colloquially used as a synonym for statistical dependence. However, “correlation” is technically only a measure of linear statistical dependence. We will largely be using the term association to refer to statistical dependence from now on.

Lets take an example from Brady Neal's Causal Course book.

Say you happen upon some data that relates wearing shoes to bed and
waking up with a headache, as one does. It turns out that most times
that someone wears shoes to bed, that person wakes up with a headache.
And most times someone doesn’t wear shoes to bed, that person doesn’t
wake up with a headache. It is not uncommon for people to interpret
data like this (with associations) as meaning that wearing shoes to bed
causes people to wake up with headaches
, especially if they are looking
for a reason to justify not wearing shoes to bed.





We can explain how wearing shoes to bed and headaches are associated
without either being a cause of the other
. It turns out that they are
both caused by a common cause: drinking the night before.
This kind of variables are called "confounder" or lurking variable. We will call this kind of association confounding association since the association is facilitated by a confounder.

Causal Machine Learning - Part 2

The main problem motivating causal inference is that association is not causation.
If the two were the same, then causal inference would be easy. Traditional statistics and machine learning would already have causal inference solved, as measuring causation would be as simple as just looking at measures such as correlation and predictive performance in data.

Lets look at another example. Lets attempt to determine the causal effect of vitamin C intake on resistance to sickness. Let X be defined as a binary indicator representing if this subject intakes vitamin C and let Y be a binary indicator of being healthy (not getting sick). X is also referred to as the ‘treatment’ in a more general setting. Now, let C1 be the value of Y if X=1 (vitamin C is taken) and C0 be the value of Y if X=0 (vitamin C is not taken). We call C0 and C1 the potential outcomes of this experiment.

Causal Machine Learning - Part 2

For a single person, the causal effect of taking vitamin C in this context would be the difference between the expected outcome of taking vitamin C and the expected outcome of not taking vitamin C.

Causal Effect = E(C1) – E(C0)

Unfortunately, we can only ever observe one of the possible outcomes C0 or C1. We cannot perfectly reset all conditions to see the result of the opposite treatment. Instead, we can use multiple samples and calculate the association between Vitamin C and being healthy.

Association = E(Y|X=1) – E(Y|X=0)

Association as being   (1+1+1+1)/4 – (0+0+0+0)/4 = 1

Causal effect, using the unobserved outcomes*, as being (4*0 + 4*1)/4 – (4*0 + 4*1)/4 = 0

We just calculated that, in this case, association does not equal causation. Observationally, there seems to be a perfect association between taking Vitamin C intake and being healthy. However, we can see there is no causal effect because we are privileged with the values of the unobserved outcomes. This inequality could be explained by considering that the people that stayed healthy practiced healthy habits which included taking Vitamin C.

Okay, one more motivating example :

In response to a large study that studied the relationship between income and life expectancy, Vox published an article titled “Want to live longer, even if you’re poor? Then move to a big city in California” (Klein, 2016). However, as is implied by the title of the study “The Association Between Income and Life Expectancy in the United States, 2001-2014”, the study did not presume to make this recommendation and in fact the closest statement made to the Vox recommendation was “… the strongest pattern in the data was that low-income individuals tend to live longest (and have more healthful behaviors) in cities with highly educated populations, high incomes, and high levels of government expenditures, such as New York, New York, and San Francisco, California.” (Chetty et al., 2016).

Similar to the example regarding vitamin C and health, this study only found associative effects. However, just like it is incorrect to say that vitamin C causes a person to be healthy, it is also incorrect to say that moving to California will cause you to live longer.

That's all for now ! , Hope you enjoyed reading so far !

In the next blog post, we will further investigate the differences between association and causation, by starting with Pearl’s three-level causal hierarchy. That will be much interesting to watch out for !

References

  1. Simpson's Paradox - Technical Report By Judea Pearl
  2. Causal Inferences In Statistics Judea Pearl - Chapter 1
  3. Course : Causal Course - Brady Neal
]]>
<![CDATA[Introduction to Causality In Machine Learning - Part 1]]>https://amaljith.me/introduction-to-causality-in-machine-learning/Ghost__Post__639aeedafbcf61465c0f70e5Thu, 15 Dec 2022 09:59:30 GMT
Introduction to Causality In Machine Learning - Part 1

To Build Truly Intelligent Machines, Teach Them Cause and Effect.

Correlation is not Causation!.

This post is the first of the series on Causal Machine Learning. I will start with the very basics of causal inference , Provide some basic background in Bayesian networks/graphical models , Show how graphical models can be used in causal inference and Describe application scenarios , case studies and the practical difficulties in Causal Inference. I will follow step by step approach and keep the things as simple as possible with lot of practical tutorials. In each of the session i will provide additional learning materials and references , which should help you to keep the flow. In this blog post , i will present Why we need causality in Machine Learning! . Enjoy the reading!

What is Causal AI ?

Deep learning techniques do a good job at building models by correlating data points. But many AI researchers believe that more work needs to be done to understand causation and not just correlation. The field causal deep learning -- useful in determining why something happened -- is still in its infancy, and it is much more difficult to automate than neural networks.

Even though we can observe correlation, it does not prove causation.

Correlation: measures the relationship between two things.
Causation: means that one thing will cause the other to happen.
  • I know that when I see X, I will see Y (Association/Correlation)
    
  • I know that X causes Y (Causality)
    

The distinctions between the two can have important implications. In the website, “Spurious Correlations” by Tyler Vigen, we can explore a wide variety of correlations that are due to chance. One of the interesting spurious correlation is listed below.

Introduction to Causality In Machine Learning - Part 1

While these two variables have a correlation of 95.23%, it is highly unrealistic to think that a degree in mathematics caused an increase in the amount of Uranium stored in the United States!

Introduction to Causality In Machine Learning - Part 1

“If Correlation Doesn’t Imply Causation, Then What Does?”

We will uncover this in the upcoming blog posts.

The excitement in the field has been kindled by Judea Pearl, a professor at UCLA, who did some of the formative work on implementing Bayesian networks for statistical analysis. More recently he has been developing a framework for diagramming causation and teasing apart the factors that contribute to observed events in a computable framework.

Introduction to Causality In Machine Learning - Part 1

In his latest book, “The Book of Why: The New Science of Cause and Effect,” he argues that artificial intelligence has been handicapped by an incomplete understanding of what intelligence really is. In his new book, Pearl, elaborates a vision for how truly intelligent machines would think. The key, he argues, is to replace reasoning by association with causal reasoning. Instead of the mere ability to correlate fever and malaria, machines need the capacity to reason that malaria causes fever. Pearl expects that causal reasoning could provide machines with human-level intelligence.

Introduction to Causality In Machine Learning - Part 1

Understanding why requires understanding of the whats, the wheres, and the whens. The hows, however, seem to be an implementation of the whys !!

Traditional ML Vs Causal ML

Machine learning is a type of artificial intelligence that involves training algorithms to recognise patterns in data and make predictions or decisions based on those patterns. The goal of machine learning is to build models that can generalise to new data and make accurate predictions or decisions.

The main difference between machine learning and causal machine learning is the focus of the analysis. While traditional machine learning aims to predict an outcome based on patterns in the data, causal machine learning aims to identify the specific variables that are causing an outcome and how they contribute to it. This involves identifying and modelling the causal relationships between variables, rather than just the statistical relationships.

Causal machine learning is a type of machine learning that focuses on identifying the cause-and-effect relationships between variables. In other words, it aims to identify the factors that influence a particular outcome and how they influence it.

Causal machine learning can be used to improve the accuracy of predictive models by taking into account the underlying causes of the outcomes being predicted. It is also useful in a variety of applications, such as evaluating the effectiveness of interventions, predicting the impact of policy changes, and identifying the factors that contribute to certain outcomes.

Explainable AI vs Causal AI

Explainable AI (XAI) is a type of artificial intelligence (AI) that is designed to be transparent and interpretable, meaning that it can provide explanations for its decisions and actions. The goal of XAI is to make AI systems more transparent and understandable to humans, so that they can be trusted and used more effectively.

Causal AI, on the other hand, is a type of AI that focuses on identifying the cause-and-effect relationships between variables. It is a sub field of machine learning that aims to identify the specific factors that influence a particular outcome and how they contribute to it. One key difference between explainable AI and causal AI is their focus. Explainable AI is concerned with making AI systems more transparent and interpretable, while causal AI is focused on identifying the causes and effects of various phenomena.

Another difference is the techniques used. Explainable AI often employs techniques such as feature importance, sensitivity analysis, and model interpretation methods to provide insights into the decision-making process of AI systems. Causal AI, on the other hand, typically uses techniques such as structural equation modelling, instrumental variables, and counterfactual analysis to identify the causal relationships between variables.

While XAI and causal AI are related in that they both aim to increase our understanding of how AI systems work, they are distinct concepts. XAI focuses on providing explanations for the decisions and predictions made by AI systems, while causal AI focuses on identifying the underlying causes of outcomes.

One way in which XAI and causal AI can be related is that XAI methods, such as counterfactual analysis, can be used to identify the causes of particular outcomes or decisions. However, it is important to note that not all XAI methods are causal in nature, and not all causal AI systems are necessarily explainable. Overall, both XAI and causal AI are important tools for improving our understanding of how AI systems work and for increasing the transparency and trustworthiness of AI systems.

Applications

Causal machine learning can be applied in many different fields and industries to identify and understand the causal relationships between variables. Here are a few examples of the application of causal machine learning:

  1. Healthcare: Causal machine learning can be used to identify the factors that contribute to the development of certain diseases and to predict the likelihood of future events, such as hospital re-admissions. It can also be used to understand the factors that influence patient outcomes and to develop personalised treatment plans.
  2. Finance: Causal machine learning can be used to understand the factors that influence stock prices and to develop trading strategies. It can also be used to identify the causes of financial fraud and to develop strategies to prevent it.
  3. Marketing: Causal machine learning can be used to understand the factors that influence customer behaviour and to optimize marketing campaigns. It can also be used to identify the factors that drive customer loyalty and to develop strategies to retain customers.
  4. Education: Causal machine learning can be used to understand the factors that influence student learning and to develop personalized learning strategies. It can also be used to identify the causes of academic achievement gaps and to develop strategies to address them.
  5. Social science: Causal machine learning can be used to understand the factors that influence social outcomes and to develop policies that address social issues. It can also be used to identify the causes of social inequality and to develop strategies to address it.

These are just a few examples of the many ways in which causal machine learning can be applied. There are many more applications in various fields and industries.

Conclusion

In this post I have provided an introduction to Causal machine learning. I have tried to be as compact as possible. Below you can find some additional resources if you want to know more about Causal machine learning. Hope you enjoyed reading so far!.

References

  1. Textbook : Causal Machine Learning - Mannings

  2. Paper : Causal Machine Learning: A Survey and Open Problems, 2022. Jean Kaddour, Aengus Lynch, Qi Liu, Matt J. Kusner, Ricardo Silva.

  3. Workshop : NeurIPS 2021 Workshop

  4. Course : Machine Learning & Causal Inference: A Short Course

  5. Texbook : Causal inference in statistics:An overview. Judea Pearl

  6. Industry : Causality and Machine Learning: Microsoft Research

]]>
<![CDATA[Shapley Additive Explanations (SHAP)]]>https://amaljith.me/shapley-additive-explanations-shap/Ghost__Post__63ff26ec72a3c427182edd36Wed, 01 Mar 2023 10:36:46 GMT

In this article , we will talk about SHAP in detail. We will discuss What are Shapley Values ? , Mathematical foundation behind the Shapley Values and How does SHAP (Shapley Additive Explanations) reframes the Shapey Value problem in detail. Also we will discuss What is Local Accuracy, Missingness, and Consistency in the context of explainable models , What is the Shapley Kernel etc.

What is Shapley Values ?

SHAP values were introduced  by Lundberg and Lee (2016) as a way to provide local explanations for machine learning models. They built upon Shapley's work in cooperative game theory, using the Shapley value to explain how each feature in a model contributes to the prediction for a particular instance.

Shapley values were invented by Lloyd Shapley as a way of providing a fair solution to the following question: if we have a coalition C that collaborates to produce a value V, how much did each individual member contribute to that final value ?

So what does this mean ? We have a coalition C, a group of cooperating members that work together to produce some value V, called the coalition value. This could be something like, a corporation of employees that together generate a certain profit, or a dinner group running up a restaurant bill. We want to know exactly how much each member contributed to that final coalition value; what share of the profit does each employee deserve, how much each person in the dinner party owes to settle the bill.

Shapley Additive Explanations (SHAP)

However, answering this gets tricky when there are interacting effects between members, when certain permutations cause members to contribute more than the sum of their parts. To find a fair answer to this question that takes into account these interaction effects, we can compute the Shapley value for each member of the coalition.

So let’s how we can compute the Shapley value for member 1 of our example coalition. The way this is done is by sampling a coalition that contains member 1, and then looking at the coalition formed by removing that member.

Shapley Additive Explanations (SHAP)

We then look at the respective values of these two coalitions, and compare the difference between the two.

Shapley Additive Explanations (SHAP)

This difference is the marginal contribution of member 1 to the coalition consisting of members 2, 3, and 4; how much member 1 contributed to that specific group.

Shapley Additive Explanations (SHAP)

So we then enumerate all such pairs of coalitions, that is, all pairs of coalitions that only differ based on whether or not member 1 is included, and then look at all the marginal contributions for each.

Shapley Additive Explanations (SHAP)

The mean marginal contribution is the Shapley value of that member.

Shapley Additive Explanations (SHAP)

We can do this same process for each member of the coalition, and we’ve found a fair solution  to our original question.!

Mathematically, the whole process looks like this, but all we need is to know that the Shapley value is the average amount of contribution that a particular member makes to the coalition value.

Shapley Values To SHAP

Now, translating this concept to model explainability is relatively straightforward, and that’s exactly what Scott Lundberg and Su-In Lee did in 2017 with their paper “A Unified Approach to Interpreting Model Predictions,” where they introduced SHAP.

Shapley Additive Explanations (SHAP)

SHAP reframes the Shapley value problem from one where we look at how members of a coalition contribute to a coalition value to one where we look at how individual features contribute to a model’s outputs.

Shapley Additive Explanations (SHAP)

They do this in a very specific way, one that we can get a clue to by looking at the name of their algorithm; Shapley Additive Explanations. We know what Shapley values are, we know what Explanations are, but what do they mean by Additive?

Lundberg and Lee define an additive feature attribution as follows: if we have a set a of inputs x, and a model f(x), we can define a set of simplified local inputs x’ (which usually means that we turn a feature vector into a discrete binary vector, where features are either included or excluded) and we can also define an explanatory model g.

What we need to ensure is that One: if x’ is roughly equal to x then g(x’) should be roughly equal to f(x)

Shapley Additive Explanations (SHAP)

two: g must take below form, where phi_0 is the null output of the model, that is, the average output of the model, and phi_i is the explained effect of feature_i; how much that feature changes the output of the model. This is called it’s attribution.

Shapley Additive Explanations (SHAP)

If we have these two, we have an explanatory model that has additive feature attribution. The advantage of this form of explanation is really easy to interpret; we can see the exact contribution and importance of each feature just by looking at the phi values.

Local Accuracy, Missingness and Consistency

Now Lundberg and Lee go on to describe a set of three desirable properties of such an additive feature method; local accuracy, missingness, and consistency.

Local Accuracy

Local accuracy : it simply says if the input and the simplified input are roughly the same, then the actual model and the explanatory model should produce roughly the same output.

Missingness

Missingness states that if a feature is excluded from the model, it’s attribution must be zero; that is, the only thing that can affect the output of the explanation model is the inclusion of features, not the exclusion.

Consistency

Finally, we have consistency (and this one’s a little hard to represent mathematically), but it states that if the original model changes so that the a particular feature’s contribution changes, the attribution in the explanatory model cannot change in the opposite direction;

So for example, if we have a new model where a specific feature has a more positive contribution than in the original; the attribution in our new explanatory model cannot decrease.

Shapley Additive Explanations (SHAP)

Now while a bunch of different explanation methods satisfy some of these properties, Lundberg and Lee argue that only SHAP satisfies all three; if the feature attributions in our additive explanatory model are specifically chosen to be the shapley values of those features, then all three properties are upheld.

Shapley Kernel

The problem with SHAP, however, is that computing Shapley values means you have to sample the coalition values for each possible feature permutation, which in a model explainability setting means we have to evaluate our model that number of times.

For a model that operates over 4 features, it’s easy enough, it’s just 16 coalitions to sample to get all the Shapley values. For 32 features, that’s over 17 billion samples, which is entirely untenable. To get around this, Lundberg and Lee devise the Shapley Kernel, a means of approximating shapley values through much fewer samples.

So what we do is we pass samples through the model, of various feature permutations of the particular datapoint that we’re trying to explain.

Shapley Additive Explanations (SHAP)

Of course, most ML models won’t just let you omit a feature !

Shapley Additive Explanations (SHAP)

So what we do is define a background dataset B, one that contains a set of representative datapoints that the model was trained over.

Shapley Additive Explanations (SHAP)

We then fill in our omitted feature or features with values from the background dataset, while holding the features that are included in the permutation fixed to their original values.

Shapley Additive Explanations (SHAP)

We then take the average of the model output over all of these new synthetic datapoints as our model output for that feature permutation, which we’ll call that y bar.

Shapley Additive Explanations (SHAP) Shapley Additive Explanations (SHAP)

So once we have a number of samples computed in this way,

Shapley Additive Explanations (SHAP)

We can formulate this as a weighted linear regression, with each feature assigned a coefficient.

Shapley Additive Explanations (SHAP)

With a very specific choice of weighting for each sample, based on a combination of the total number of features in the model, the number of coalitions with the same number of features as this particular sample, and the number of features included and excluded in this permutation, we ensure that the solution to this weighted linear regression is such that the returned coefficients are equivalent to the Shapley values.

Shapley Additive Explanations (SHAP)

This weighting scheme is the basis of the Shapley Kernel, and the weighted linear regression process as a whole is Kernel SHAP.

Shapley Additive Explanations (SHAP)

Now, there are a lot of other forms of SHAP that are presented in the paper (Deep SHAP, Low Order SHAP , Max SHAP , Linear SHAP , Tree SHAP etc) , ones that make use of model-specific assumptions and optimizations to speed up the algorithm and the sampling process, but Kernel SHAP is the one among them that is universal and can be applied to any type of machine learning model. This general applicability is why we chose Kernel SHAP as the first form of SHAP to implement for TrustyAI.

Kernel SHAP Example

I’ll run through an example of the Python SHAP implementation provided by Lundberg and Lee. So first I’ll grab a dataset to run our example over, and I’ve picked the Boston housing price dataset, which is a dataset consisting of various attributes about Boston neighborhoods and the corresponding house prices within that neighborhood.

Incomplete. Coming soon

]]>
<![CDATA[Explaining Bayesian Neural Networks]]>https://amaljith.me/explaining-bayesian-neural-networks/Ghost__Post__63eeea8172a3c427182edcc0Fri, 17 Feb 2023 02:52:35 GMT

Explainable AI refers to models that can easily be interpreted by humans. Bayesian inferencing is a natural choice to obtain explanations of trained deep learning models.

]]>
<![CDATA[Causal Machine Learning - Part 5]]>https://amaljith.me/causal-machine-learning-part-5/Ghost__Post__63b58208bdc6867fe35526ffWed, 04 Jan 2023 13:42:15 GMT

This post is the fifth post of the series on Causal Machine Learning. As stated before, the starting point for all causal inference is a causal model. Usually, however, we don’t have a good causal model in hand. This is where Causal Discovery can be helpful. In this post Causal Discovery will be discussed in detail.  As always i will try to keep the things as simple as possible. So stay with me , Enjoy reading !

What is Causal Discovery?

Causal inference focuses on estimating the causal effect of a specific intervention or exposure on an outcome.
Causal discovery focuses on identifying the underlying causal relationships between variables in a system.

Causal inference, which aims to answer questions involving cause and effect. As stated before, the starting point for all causal inference is a causal model. Usually, however, we don’t have a good causal model in hand. This is where Causal Discovery can be helpful.

Causal discovery aims to infer causal structure from data. In other words, given a dataset, derive a causal model that describes it.

Finding causal relationships is one of the fundamental tasks in science. A widely used approach is randomized experiments. For example, to examine whether a recently developed medicine is useful for cancer treatment, researchers recruit subjects and randomly divide subjects into two groups. One is the control group, where the subjects are given placebo, and the other is the treatment group, where the subjects are given the newly developed drug. The reason of randomization is to remove possible effects from confounders. For example, age can be one of the possible confounders which affects both taking the drug or not and the treatment effect. Thus, in practical experiments, we should keep the distribution of ages in the two groups almost the same.

How Does It Work ?

However, in many cases, randomized experiments are very expensive and hard to implement, and sometimes it may even involve ethical issues. In recent decades, inferring causal relations from purely observational data, known as the task of causal discovery, has drawn much attention in machine learning, philosophy, statistics, and computer science.

Causal discovery is an example of an inverse problem. This is like predicting the shape of an ice cube based on the puddle it left on the kitchen counter. Clearly, this is a hard problem, since any number of shapes could generate the same puddle. Connecting this to causality, the puddle of water is like statistical associations embedded in data, and the ice cube is the like underlying causal model.

Causal Discovery Assumptions & Properties

The usual approach to solving inverse problems is to make assumptions about what you are trying to uncover. This narrows down the possible solutions and hopefully makes the problem solvable. There are four common assumptions made across causal discovery algorithms.

👉 Acyclicity — Causal structure can be represented by DAG (G)

👀 Markov Property — All nodes are independent of their non-descendants when conditioned on their parents

🙃 Faithfulness — All conditional independences in true underlying distribution p are represented in G

👍 Sufficiency — Any pair of nodes in G has no common external cause

Although these assumptions help narrow down the number of possible models, they do not fully solve the problem. This is where a few tricks/tests for causal discovery are helpful. There is no single method for causal discovery that dominates all others. Although most methods use the assumptions above (perhaps even more), the details of different algorithms can vary tremendously. A taxonomy of algorithms based on the following tricks is given in the figure below.

Causal Machine Learning - Part 5

Conditional Independence Testing

One of these earliest causal discovery algorithms is the PC algorithm named after its authors Peter Spirtes and Clark Glymour. This algorithm (and others like it) use the idea that two statistically independent variables are not causally linked. The PC algorithm is illustrative of this first trick. An outline of the algorithm is given in the figure below.

Causal Machine Learning - Part 5

The first step is to form a fully connected, undirected graph using every variable in the dataset. Next, edges are deleted if the corresponding variables are independent. Then, connected edges undergo conditional independence testing e.g. independence test of the bottom and far right node conditioned on the middle node in the figure above (step 2).

If conditioning on a variable kills the dependence, that variable is added to the Separation set for those two variables. Depending on the size of the graph, conditional independence testing will continue (i.e. condition on more variables) until there are no more candidates for testing.

Next, colliders (i.e. X → Y ← Z) are oriented based on the Separation set of node pairs. Finally, the remaining edges are directed based on 2 constraints, 1) no new v-structures, and 2) no directed cycles can be formed.

Greedy Search of Graph Space

A greedy search is a way to navigate a space such that you always move in a direction that seems most beneficial based on the local surroundings. Although greedy searches cannot guarantee an optimal solution, for most problems the space of possible DAGs is so big that finding a true optimal solution is intractable. The Greedy Equivalence Search (GES) algorithm uses this trick. GES starts with an empty graph and iteratively adds directed edges such that the improvement in a model fitness measure (i.e. score) is maximized. An example score is the Bayesian Information Criterion (BIC)

Exploiting Asymmetries

A fundamental property of causality is asymmetry. A could cause B, but B may not cause A. There is a large space of algorithms that leverage this idea to select between causal model candidates.

Functional asymmetry assumes models that better fit a relationship are better candidates. For example, given two variables X and Y, the nonlinear additive noise model (NANM) performs a nonlinear regression between X and Y, e.g. y = f(x) + n, where n = noise/residual, in both directions. The model (i.e. causation) is then accepted if the potential cause (e.g. x) is independent of the noise term (e.g. n).

Conclusion

There is no way I could fit a comprehensive review of causal discovery in a short blog post. Despite being young, causal discovery is a promising field that may help bridge the gap between machine and human knowledge.

References

Causal Deep Learning

]]>
<![CDATA[Causal Machine Learning - Part 4]]>https://amaljith.me/causal-machine-learning-part-4/Ghost__Post__63b57b53bdc6867fe35526d6Wed, 04 Jan 2023 13:14:43 GMT

This post is the fourth post of the series on Causal Machine Learning. This blog post is based on the work of Judea Pearl. We have so far discussed about Causal AI , How to represent causality using SCMs , How naive statistics can fail (Spurious Correlations , Simpson Paradox & Asymmetry In Causal Inference) , Pearl's Causal Hierarchy and gave flavors of Causal Inferences & Causal Discovery etc. As always i will try to keep the things as simple as possible. So stay with me , Enjoy reading !

How are Causal AI models different from Bayesian networks?

At first glance there, there could be some ambiguities you feel while trying to explore Bayesian Networks and Causal Networks. This is completely normal. Lets try to uncover the differences before going ahead!.

Bayesian networks and Causal AI models appear similar. But Causal AI models capture underlying causal relationships; Bayesian networks just describe patterns of correlations.

What Are Bayesian Networks ?

You remember the example we discussed earlier about the data describing people’s sleeping habits. We found that there’s a strong correlation between falling asleep with shoes on and waking up with a headache.

Causal Machine Learning - Part 4

A Bayesian network representing this is given below.

Causal Machine Learning - Part 4

The BN tells us that both sleeping with shoes on and waking up with a migraine are correlated with drinking the night before, since there is a path between the variables. It also says that conditional on us knowing that someone was drinking the night before, knowing that they slept with their shoes on tells us absolutely nothing extra about whether they have a headache the next morning (this is called “conditional independence”). We can read off the conditional independence relationship by noticing that drinking alcohol “blocks” the pathway from shoe- sleeping to headache. BNs help to draw conclusions when more data becomes available (via “Bayes’ theorem”)

What Are Causal Networks ?

BNs sound useful! What’s the catch? The core problem is that Bayesian networks are blind to causality. This key, missing ingredient makes BNs very limited when it comes to more sophisticated reasoning and decision-making challenges.

Causal AI is a new category of machine intelligence. Causal AI builds models that are able to capture cause- effect relationships while also retaining the benefits of BNs.

Causal Machine Learning - Part 4 Causal Machine Learning - Part 4

Many BNs are all statistically compatible with the data, but only one BN corresponds to the genuine causal relationships in the system. As a result, it’s always left ambiguous whether your BN is a good causal model or not. And the overwhelming chances are that your BN is not a good causal model. The number of possible BNs grows exponentially as the number of features increases. With, say, 20 variables in your data, there’s effectively zero chance of randomly stumbling across the true causal model. This means you’re using a BN that’s making bad modeling decisions.

Hope this clarifies the differences and ambiguities between Bayesian and Causal Networks.

Causal Inferences

Causal inference refers to the process of drawing conclusions about the causal relationships between variables. In other words, it involves making judgments about whether changes in one variable are responsible for changes in another variable.

Here are some examples of causal inference questions:

  1. Does taking medication X reduce blood pressure in people with hypertension?
  2. Does increasing the price of cigarettes lead to a decrease in smoking rates?
  3. Does participating in an exercise program improve physical fitness?
  4. Does attending preschool lead to better academic outcomes in school?
  5. Does exposure to air pollution increase the risk of respiratory problems?
  6. Did the treatment directly help those who took it?
  7. Was it the marketing campaign that lead to increased sales this month or the holiday?
  8. How big of an effect would increased wages have on productivity?

These are just a few examples, but causal inference questions can be asked in many different fields and contexts. The key is that they are trying to understand whether a particular intervention or exposure causes a change in some outcome or dependent variable.

Do Calculus & Do Operator

Causality - Formal Definition

Before going ahead , lets again define Causality in terms of interventions.

In the context of interventions, causality refers to the relationship between an intervention (also known as a treatment or exposure) and the resulting effect on an outcome or dependent variable. A causal relationship between an intervention and an outcome means that the intervention is responsible for the observed change in the outcome. In other words, if we change the intervention, we expect to see a corresponding change in the outcome.

For example, if a medication is found to reduce blood pressure in people with hypertension, we can say that there is a causal relationship between taking the medication and lowering blood pressure. This is because we expect that if we give the medication to a group of people with hypertension, their blood pressure will decrease as a result of the intervention. However, it is important to note that there may be other factors that could have influenced the relationship between the intervention and the outcome.

What is Do-Calculus ?

In the context of causal AI, do-calculus can be used to reason about the effects of interventions on a causal model. In causal AI, a causal model represents the relationships between different variables in a system, and the do-calculus can be used to reason about how changing the value of one variable (the "intervention") will affect the values of other variables in the system. This can be useful for understanding the potential consequences of interventions in a real-world system, or for identifying the most effective intervention to achieve a particular outcome.

Here is Judea Pearl’s canonical primer on do-calculus—a short PDF with lots of math and proofs (Pearl 2012).

What do-operator does ?

However, how does that fit into causality’s mathematical representation?

The do-operator is a mathematical representation of a physical intervention.

If we start with the model Z → X → Y, we can simulate an intervention in X by deleting all the incoming arrows to X, and manually setting X to some value x0

Below is the illustration how do-operator works.

Causal Machine Learning - Part 4

Rules Of Do Calculus

Causal Machine Learning - Part 4

Beneath this scary math, each rule has specific intuition and purpose behind it! Here’s what each rule actually does:

Rule 1: Decide if we can ignore an observation
Rule 2: Decide if we can treat an intervention as an observation
Rule 3: Decide if we can ignore an intervention

Whoa! That’s exceptionally logical. Each rule is designed to help simplify and reduce nodes in a DAG by either ignoring them (Rules 1 and 3) or making it so interventions like do⁡(⋅)do(⋅) can be treated like observations instead (Rule 2).

Causal Machine Learning - Part 4

References

  1. Judea Pearl’s canonical primer on do-calculus
]]>
<![CDATA[Causal Machine Learning - Part 3]]>https://amaljith.me/causal-machine-learning-part-3/Ghost__Post__63b57b88bdc6867fe35526e0Wed, 04 Jan 2023 13:14:37 GMT

This post is the third post of the series on Causal Machine Learning. This blog post is based on the work of Judea Pearl. In this blog post i have discussed Pearl’s three-level causal hierarchy , How to represent Causality and little bit about Causal Inferences & Causal Discovery. As always i have tried to keep the things as simple as possible. So stay with me , Enjoy reading !

Causal Hierarchy

In this blog post , Lets start with Pearl’s three-level causal hierarchy. Let us further investigate the differences between association and causation, by starting with Pearl’s three-level causal hierarchy.

Causal Machine Learning - Part 3

The first level is association, the second level is intervention, and the third level is counterfactual. The first level, association, involves just seeing what is. It invokes purely statistical relationships, defined by the naked data. It can handle questions such as “What does a symptom tell me about a disease?”. The second level, intervention, ranks higher than association because ere the subjects are given the newly developed drug. The reason of randomization is to remove possible effects from confounders. For example, age can be one of the possible confounders which affects both taking the drug or not and the treatment effect. Thus, in practical experiments, we should keep the distribution of ages in the two groups almost the same. Technically, one may use propensity score matching to remove the effects from possible confounders.it involves not just seeing what is, but changing what we see. It can handle questions such as “What if I take aspirin, will my headache be cured?”. The top level is called counterfactuals. A typical question in the counterfactual category is “What if I had acted differently,” thus necessitating retrospective reasoning.

Associational: if I see X, what is the probability that I will see Y?
Interventional: if I do X, what is the probability that I will see Y?
Counterfactual: what would Y have been, had I done X?

How To Represent Causality ?

Causality is represented mathematically via Structural Causal Models (SCMs). The two key elements of SCMs are a graph and a set of equations. More specifically, the graph is a Directed Acyclic Graphs (DAG) and the set of equations is a Structural Equation Model (SEM).

The earliest known version of SCMs, were introduced by geneticist Sewell Wright around 1918, originally for infering the relative importance of factors which determine the birth weight of guinea pigs. He used the construction to develop the methodology of path analysis, a technique commonly used for causal inference tasks over layered and complex processes, such as phenotypic inheritence.

Causal Machine Learning - Part 3
Drawings from Wright's 1921 paper, Correlation and Causation. The bottom image presents an ancestor to causal graphs, a representation of structural causal models describing the relationships between a variety of genetic factors and a guinea pigs birth weight. Wright's path tracing rules defined a set of rules for using a set of associative relationships, to generate a causal graph, presented above with the top and bottom image respectively.

A DAG is a graph, comprised of nodes and edges, for which the direction of an edge determines the relationship between the two nodes on either side. DAGs also do not have any cycles or paths comprised of at least one edge that start and end with the same node.

A structural causal model is comprised of three components:

  1. A set of variables describing the state of the universe and how it relates to a particular data set we are provided. These variables are: explanatory variables, outcome variables, and unobserved variables.
  2. Causal relationships, which describe the causal effect variables have on one another.
  3. A probability distibution defined over unobserved variables in the model, describing the likelihood that each variable takes a particular value.

Causal Machine Learning - Part 3

SEMs represent relationships between variables. These equations have two peculiarities. First, equations are asymmetric meaning equality only works in one direction. This has the implication that SEMs cannot be inverted to derive alternative SEM equations. Second, equations can be non-parametric meaning the functional form is not known.

Causal Inferences & Causal Discovery

Causal inference, which aims to answer questions involving cause and effect. Although causal inference is a powerful tool, it requires a key to operate. Namely, it requires a causal model. Often in the real world, however, we may not be sure about which variables cause each other. This is where causal discovery can help.

In causal inference, the causal structure of the problem is often assumed. In other words, a DAG representing the situation is assumed. In practice, however, the causal connections of a system are often unknown. Causal discovery aims to uncover causal structure from observational data. Causal discovery aims to infer causal structure from data. In other words, given a dataset, derive a causal model that describes it.

I will describe more on causal inferences and causal discovery in the upcoming blog posts

References

  1. The Three Layer Causal Hierarchy - Judea Pearl
]]>