Causality — Understanding Counterfactuals, Attribution and the Relevance to AI development and explainability

Mondweep Chakravorty
9 min readJul 21, 2023

--

Explaining AI

In understanding our complex world, we often find ourselves asking, “What caused this?” or “What would happen if…?”. These questions, invoking the idea of cause and effect, lead us into the domain of causality. This blog post will explore the science of causality, its relevance in addressing counterfactual scenarios and in solving attribution problems.

What is Causality?

Essentially, causality is about linking cause and effect — determining how and why certain events occur due to specific factors. This seemingly simple principle underpins numerous scientific fields, from physics and chemistry to economics and social sciences. Its language is used to understand and predict phenomena, infer conclusions, and make decisions.

Causality transcends mere correlation. It tackles the ‘why’ behind the ‘what’, lending insight into not just what events occur together, but which event leads to another. The key to understanding causality is to remember this oft-repeated phrase: “Correlation does not imply causation”. This means that just because two variables move together, it does not imply that one causes the other.

Causality and Counterfactuals:

The field of causality plays a fundamental role in understanding counterfactual scenarios — hypothetical situations contrasting with reality, asking “What if things were different?”. Counterfactuals help in assessing the consequences of alternate actions, providing key insights into fields like policy-making, law, economics, and artificial intelligence.

Understanding counterfactuals requires the ability to model causal relationships accurately. For example, if you’re assessing the impact of a public health intervention, you’d need to compare the current situation (where the intervention was implemented) against a counterfactual scenario (where the intervention was not implemented). This comparison gives you the causal effect of the intervention on public health.

Causality in Attribution Problems:

Attribution problems deal with allocating the effects observed in a system to their respective causes. For instance, in digital marketing, there may be a need to understand how much each advertisement contributes to the sales of a product. Causality, with its focus on cause and effect relationships, plays a crucial role in such analyses.

It helps to distinguish between the different influences and how they interact with each other. Understanding causality is crucial for effective resource allocation, strategic planning, and evaluating interventions.

Causal Inference: The Pathway to Understanding Causality

To tackle these problems and answer these questions, reliance is often on causal inference, a set of statistical methods used to estimate causal relationships from data. It uses techniques such as randomised control trials, instrumental variables, and difference-in-differences, among others.

Causal inference enables separation of correlation from causation and to investigate the impact of specific factors while controlling for others. It’s a crucial tool in economics, epidemiology, social sciences, and increasingly in machine learning, improving understanding of the inner workings of complex models and making them more interpretable and reliable.

In conclusion, the science of causality provides a rigorous framework for understanding the world, allowing us to address ‘what if’ questions and solve attribution problems. It allows us to understand the complex network of cause-effect relationships that determine our reality, providing invaluable insights for decision-making and policy planning.

Whether we’re trying to discern the impact of a marketing campaign on product sales, understand the potential outcomes of a policy, or even predict the effects of climate change, causality provides the tools and concepts necessary to parse through these complex problems.

While still a challenging field rife with theoretical and practical complexities, the journey into the realm of causality is a necessary one for those wishing to unveil the mechanics of our interconnected world. From counterfactual conundrums to attribution puzzles, causality shines a light on the pathways that help us answer the most important question — “Why?”

Enhancing AI through the Lens of Causality

AI, specifically in the realm of machine learning, has made substantial strides in predictive accuracy. However, the so-called “black box” problem often shrouds the internal workings of these models, making it difficult to understand why a model made a particular prediction. Here, the science of causality can offer a profound contribution.

Consider a machine learning model tasked with predicting patient outcomes based on their symptoms. A traditional model may identify correlations, such as patients with symptom X often experience outcome Y. But without understanding causality, we’re left wondering: does symptom X cause outcome Y, or is there an unseen factor Z that causes both? Moreover, how would the outcome change if symptom X were treated?

Causal Insights for AI: A Framework

Weaving causal science into AI can help alleviate such concerns, offering a more reliable, understandable, and ethically aware AI system. Here is a proposed framework:

  1. Data Collection and Pre-processing: This first step remains similar to traditional machine learning. We gather and clean the data, ensuring its quality and relevance. However, causal AI requires careful consideration of the variables included, aiming to capture not just correlates but potential causal factors.
  2. Building Causal Models: Instead of jumping directly into pattern recognition, we construct causal models, often represented as directed acyclic graphs (DAGs). These models capture our assumptions about how the world works, indicating the cause-effect relationships among variables.
  3. Model Training and Refinement: Train the AI model on the collected data, but guided by the causal framework. The causal model can be used to define the architecture of the AI system, influencing the structure of neural networks or the construction of decision trees. Regular machine learning techniques can then be applied to refine the model parameters.
  4. Causal Testing and Validation: Test the AI system, looking not just at prediction accuracy but also causal validity. Does the system’s understanding of cause-effect match empirical evidence? If not, the model needs refining, either in its structure or parameters.
  5. Interpretation and Decision Making: With a causal AI system, predictions come with an understanding of why they were made. This allows us to interpret results in light of cause-effect relationships, making AI systems more transparent and trustable.

Reaping the Benefits:

With this framework, we can enhance AI development in numerous ways:

1. Understanding ‘Why’: In traditional AI, a system might accurately predict that a patient with a certain genetic marker is likely to develop a disease. With causal AI, we can go a step further and understand why that genetic marker leads to the disease, thereby providing a path to intervention.

2. Improved Generalisation: Causal models are more robust to changes in the environment — a crucial advantage in real-world applications. For example, a machine learning model trained on past data may fail if the market dynamics change, while a causal model, understanding the underlying cause-effect relationships, can adapt to these changes.

3. Counterfactual Reasoning: A causal AI can handle counterfactual queries like, “What would have happened had we not launched that marketing campaign?” This ability can offer invaluable insights for decision-making processes.

4. Ethical Considerations: By understanding the causal factors behind predictions, we can ensure that AI systems don’t inadvertently discriminate based on sensitive variables like race or gender.

In conclusion, while AI has made significant strides in recent years, the inclusion of causal sciences offers an exciting new frontier for AI development. By enabling AI to understand and reason about the world in terms of cause and effect, we can make these systems more reliable, understandable, and ethically responsible.

Tooling that can assist with the Causal Insights for AI framework could be as follows:

  1. Data Collection and Pre-processing
  • Pandas: A Python library that provides extensive means for data analysis. It allows for reading and writing data between in-memory data structures and various file formats.
  • PyTorch: More than just a deep learning library, PyTorch also offers a wide array of tools for data loading and preprocessing.
  • TensorFlow Datasets: A collection of datasets ready to use with TensorFlow, along with the tools for loading and preprocessing them.
  • Apache Kafka: A distributed streaming platform capable of handling trillions of events a day. It provides real-time data feeds and a robust platform for stream processing.

2. Building Causal Models

  • pgmpy: A Python library for working with Probabilistic Graphical Models. It allows you to create various types of Bayesian and Markov models and perform exact or approximate inference on them.
  • Tetrad: A tool developed by the University of Pittsburgh for creating, simulating, and analysing causal models (particularly DAGs).
  • CausalNex: A Python library that allows data scientists to incorporate their domain knowledge in probabilistic graphical models, learning structures from data and making causal inferences.
  • DoWhy: A Python library that makes causal inference easy. It provides a unified interface for causal inference methods and automatically tests many assumptions, speeding up robustness checks.

3. Model Training and Refinement

  • Pyro: A universal probabilistic programming language (PPL) written in Python and supported by PyTorch. Pyro enables flexible and expressive deep probabilistic modelling, unifying the best of modern deep learning and Bayesian modelling.
  • NeuroCAUSAL: This tool helps uncover the brain’s causal connectivity patterns from functional magnetic resonance imaging (fMRI) data.
    CausalNets: A Python library that combines causal reasoning and deep learning for interpretable predictive modelling.
  • TensorFlow and PyTorch: Popular frameworks for deep learning that offer comprehensive libraries for Machine Learning and other complex computations.
  • Keras: A high-level neural networks API capable of running on top of TensorFlow. It allows for easy and fast prototyping and supports both convolutional networks and recurrent networks.
  • Scikit-learn: A Python library that provides simple and efficient tools for predictive data analysis. It features various algorithms for classification, regression, clustering, and dimensionality reduction.

4. Causal Testing and Validation

  • EconML: A Python package developed by Microsoft that uses machine learning to build heterogeneous treatment effect models. EconML provides a suite of methods to estimate the effect of a treatment, policy, or intervention.
  • DoWhy: Already mentioned above, it is also useful for testing the causal assumptions and validating the causal effect.
  • CausalML: A Python package that provides a suite of uplift modelling and causal inference methods. The package leverages machine learning algorithms to estimate the Conditional Average Treatment Effect (CATE).
  • CausalImpact: An R package developed by Google. It provides causal inference using Bayesian structural time-series models. The package implements an approach to estimate the causal effect of a designed intervention on a time series.

5. Interpretation and Decision Making

  • Captum: A model interpretability library for PyTorch. It provides a unified and easy-to-use API for feature attribution, and it supports a wide range of state-of-the-art interpretability algorithms.
  • Lucid: A flexible and easy-to-use library for visualising neural networks, allowing us to better understand, interpret, and refine our models.
  • Alibi Explain: This is an open-source Python library aimed at machine learning model inspection and interpretation. The focus of the library is to provide high-quality implementations of black-box, white-box, local, and global explanation methods.
  • SHAP (SHapley Additive exPlanations): A unified measure of feature importance that allocates the contribution of each feature to the prediction for each sample.
  • LIME (Local Interpretable Model-agnostic Explanations): An approach to explain predictions of any machine learning classifier or regressor in a faithful way, by approximating it locally with an interpretable model.
  • What-if Tool: Developed by Google, it provides an easy-to-use interface for understanding a trained machine learning model. It allows you to visualise model results and perform counterfactual analysis.

The suggested libraries offer capabilities for each step of the process, enabling the development of transparent, ethical AI systems powered by causal insights. This visual framework provides an actionable guide for implementing causal AI in practice.

There also exist proprietary platforms that have integrated some of the tooling to provide a joined up experience for exploring causality and developing explainable AI solutions. One of those platform providers is Geminos.AI. Another such platform is causaLens. Geminos.AI’s Causeway platform uses causal models to remove complexity and increase explainability by providing a common language between data scientists and the business underpinned by the science of causality. To learn more about this topic and explore relevance to use cases relevant to you, do feel free to reach me at mondweep@bridgeconnect.biz. At CBS Consulting, we act as leaders in delivering sustainable change programmes.

Disclosure:

Although this article has leveraged Generative AI capabilities from Claude 2 and ChatGPT4.0, I have validated the content based on my study and research of the topic. Citation has been included below.

To delve into the details, here are some useful references:

--

--

No responses yet