概要
Causing: CAUSal INterpretation using Graphs — individual total and mediation effects of equation systems as colored graphs (explainable AI)
AI・機械学習計測したスター増加
- 24時間
- 0
- 7日間
- 0
- 15日間
- 0
- 1か月
- 履歴を収集中
期間ごとの純増数です。期間は重複しており、日別の値ではありません。未計測の値は空欄です。スター数は注目度の指標であり、品質の保証ではありません。
README.md
オリジナル
Installation · Quickstart · Examples · Video · Publications · Citation
Explain why each observation differs from the average — as a colored causal graph.
Why does this worker earn less than average? A low test score outweighs a well-educated father.
Causing is a multivariate graphical analysis tool for Python that explains the causal effects of a given equation system. For every single observation it shows how much each variable contributes to the outcome — and through which paths. You get one colored graph of total and mediation effects per observation, even for highly nonlinear systems.
- Input: a dataset and an equation system in the form of SymPy equations. The variables on the left-hand side are caused by the variables on the right-hand side — you provide the causal structure as a directed acyclic graph (DAG).
- Output: a colored graph of quantified effects between the model variables: green pushes the result up, red pushes it down, grey means a small effect, and the thickness shows how strongly.
Why Causing?
🎯 Individual effectsNot just averages: every observation gets its own explanation — a company, a customer, a patient. |
🔀 Total and mediation effectsOne graph shows the overall effect of each variable and how it flows through the intermediate variables to the outcome. |
🧮 Nonlinear and latentWorks with any equation system SymPy can express — including |
🔍 Transparent by constructionA white-box structural model instead of a black box: explainable AI (XAI) that is easy to communicate to decision makers and regulators. |
⚡ LightweightBuilt on the standard scientific Python stack (NumPy, SciPy, SymPy), graphs via Graphviz. No deep-learning framework, no GPU. |
🏭 Proven in practiceThe engine behind RealRate's AI-based financial strength ratings of insurance companies, published in a peer-reviewed journal and a Springer volume (see Publications). |
🏆 3rd place, Responsible AI Development Tools — Global PyTorch Summer Hackathon 2020 (see Award)
Installation
pip install causing # or: uv add causing
Causing requires Python 3.9 or newer. To draw the graphs, Graphviz must be
installed (e.g. apt install graphviz, brew install graphviz or conda install graphviz).
Quickstart
This reproduces the graph at the top of this page — a simplified version of the education example with real data:
from pathlib import Path
import numpy as np
from sympy import symbols
import causing.graph
from causing import Model
# 1. Your model: the equations in order of computation
FatherEdu, Ability, Education, Wage = symbols(["FatherEdu", "Ability", "Education", "Wage"])
m = Model(
xvars=[FatherEdu, Ability], # observed causes
yvars=[Education, Wage], # caused variables, in order of computation
equations=(
11.8 + 0.1 * FatherEdu, # Education in years of schooling
Education + Ability - 5, # Wage in dollars per hour
),
final_var=Wage, # the result to explain
)
# 2. Your data: 17,919 observations of young U.S. workers (NLSY), one column per observation
url = "https://raw.githubusercontent.com/realrate/Causing/develop/causing/examples/input/education.csv"
data = np.loadtxt(url, delimiter=",").reshape(-1, 10).T
xdat = data[[7, 5]] # father's education, ability (test score)
# 3. Your answer: the effects for every observation, the graph for observation no. 164
effects = m.calc_effects(xdat)
graphs = causing.graph.annotated_graphs(m, effects, ids=[str(i) for i in range(xdat.shape[1])])
causing.graph.create_graphs([g for g in graphs if g.graph["id"] == "164"], Path("output"))
The graph is written as SVG file output/IME_164.svg. Worker no. 164 has a father with 17 years of
schooling (average: 11.7), which adds +0.53 $/h via his own education, but a low test score costs
−0.99 $/h — in total he earns 0.46 $/h less than the average.
How it works
For each observation, Causing sets one variable at a time to its average value and recomputes the whole equation system — all downstream variables adjust. The resulting change of the final variable is the total effect of that variable for this observation. This is an intervention in the sense of Pearl's do-calculus; for small changes it corresponds to the total derivative used in the 2020 paper.
- Node values show the total effect of a variable on the final variable of interest.
- Edge values split this total effect over the outgoing edges: these are the mediation effects. Outgoing edges sum up to the node value; incoming edges do not.
- All effects are measured relative to the average of all observations, so every observation can be benchmarked against the average.
The graph combining total and mediation effects is called the Individual Mediation Effects (IME) graph.
| Causing is | Causing is NOT |
|---|---|
| ✅ causal model given | ❌ causal search / discovery |
| ✅ DAG — directed acyclic graph | ❌ cyclic, undirected, or bidirected graph |
| ✅ structural model | ❌ reduced model |
| ✅ small and big data | ❌ big data requirement |
The most important restriction is that you need to specify the causal model, i.e. the causal ordering. Exogenous variables are assumed to be observed and deterministic; many endogenous variables may be unobserved.
Examples
The wage model at the top of this page is a simplified version of the education example (two of its three
equations, same coefficients). All examples are in
causing/examples/models.py.
After cloning the repository, run any of them with python -m causing.examples <name>; the graphs are
written as SVG files to the output folder.
| Example | What it shows | Name |
|---|---|---|
| Simple model | latent variables, nonlinear mediation chain (below) | example |
| Education and wages | real-world data: wages of young American workers | education |
| Direct observation | single equation, no latent variables | example2 |
| Opposing effects | a positive and a negative path that partly cancel | example3 |
| Kink at zero | Max(X, 0) — non-smooth functions |
heaviside |
Example 1: a simple model
Y1 = X1
Y2 = X2 + 2 · Y1²
Y3 = Y1 + Y2 (final variable of interest)
The data consists of 200 observations with mean(X1) = 3 and mean(X2) = 2. Y1 and Y2 are latent (unobserved), Y3 is observed.
The graph below shows observation no. 1. There is one green path from X1 through Y1 and Y2 to Y3: X1 is the main cause for Y3 being above average, with an effect of +29.8. This is slightly reduced by X2 (−0.968). In total, Y3 is +27.1 above average. (In nonlinear models the effects need not add up exactly — here because of the Y1² term.) You understand at one glance why.
Example 2: education and wages
A real-world example from social sciences: how the wage earned by young American workers is determined by their educational attainment, family characteristics, and test scores. The data are from Koop and Tobias (2004) — 17,919 observations of 2,178 individuals from the National Longitudinal Survey of Youth (NLSY). The graph below explains the wage of observation no. 32: an above-average father's education raises his own education and thus the wage, while the age-driven potential experience lowers it.
- 🎬 5-minute introductory video: Causing Introduction Video
- 📄 Detailed analysis: Example: Education and Wages
Example 3: insurance ratings
RealRate uses Causing to rate the financial strength of insurance companies and to explain each rating — which balance sheet and income figures drive a company's rating up or down. The method is introduced in Bartel (2020), where the equation system is represented as a sparse structural neural network whose nodes are the model variables and whose edge weights are the effects; see the publications.
Award
Causing won 3rd place in the category Responsible AI Development Tools at the Global PyTorch Summer Hackathon 2020 — among more than 2,500 participants from 114 countries (announcement, project page). The prize-winning version was written single-handedly by Holger Bartel — an economist and data scientist, not a professional software developer, and in the days before AI coding assistants.
At that time, Causing used PyTorch to estimate the model parameters. Since 2022, parameter estimation is part of RealRate's rating engine, and the open-source library concentrates on what makes Causing unique: the causal interpretation of a given model. This needs only the standard scientific Python stack, so Causing stays small and easy to install — and you can plug in parameters estimated with PyTorch or any other tool.
Publications
Publications on Causing and its application to insurance ratings:
- Bartel, H. (2020). Causal Analysis — With an Application to Insurance Ratings. DOI: 10.13140/RG.2.2.31524.83848 · ResearchGate
- Bartel, H. (2020). Explainable Artificial Intelligence (XAI) in Ratings. Talk, KI Community Meetup. ResearchGate
- Bartel, H., Kraft, M., & Leidner, J. L. (2023). Erklärbare Künstliche Intelligenz am Beispiel von Ratings deutscher Lebensversicherungsunternehmen [in German]. Zeitschrift für die gesamte Versicherungswissenschaft, 112, 3–32. DOI: 10.3790/zverswiss.2023.04.Bartel.etal
- Bartel, H., Kraft, M., & Leidner, J. L. (2023). Erklärbare Künstliche Intelligenz und Geschäftsmodell am Beispiel von Unternehmensratings [in German]. In L. Heim & S. Gerth (Eds.), Entrepreneurship der Zukunft. Springer Gabler. DOI: 10.1007/978-3-658-42060-4_8
More publications: realrate.ai/scientific-publications
Further reading
Causing builds on the classical literature on path analysis, structural equation models, and causal mediation analysis:
- Wright, S. (1921). Correlation and Causation. Journal of Agricultural Research, 20(7), 557–585.
- Wright, S. (1934). The Method of Path Coefficients. Annals of Mathematical Statistics, 5(3), 161–215. DOI: 10.1214/aoms/1177732676
- Baron, R. M., & Kenny, D. A. (1986). The Moderator–Mediator Variable Distinction in Social Psychological Research. Journal of Personality and Social Psychology, 51(6), 1173–1182. DOI: 10.1037/0022-3514.51.6.1173
- Bollen, K. A. (1989). Structural Equations with Latent Variables. Wiley. DOI: 10.1002/9781118619179
- Robins, J. M., & Greenland, S. (1992). Identifiability and Exchangeability for Direct and Indirect Effects. Epidemiology, 3(2), 143–155. DOI: 10.1097/00001648-199203000-00013
- Pearl, J. (2001). Direct and Indirect Effects. Proceedings of the 17th Conference on Uncertainty in Artificial Intelligence (UAI), 411–420.
- Koop, G., & Tobias, J. L. (2004). Learning about Heterogeneity in Returns to Schooling. Journal of Applied Econometrics, 19(7), 827–849. DOI: 10.1002/jae.744
- Pearl, J. (2009). Causality: Models, Reasoning, and Inference (2nd ed.). Cambridge University Press. DOI: 10.1017/CBO9780511803161
- Imai, K., Keele, L., & Tingley, D. (2010). A General Approach to Causal Mediation Analysis. Psychological Methods, 15(4), 309–334. DOI: 10.1037/a0020761
- VanderWeele, T. J. (2015). Explanation in Causal Inference: Methods for Mediation and Interaction. Oxford University Press.
Citation
If you use Causing in your research, please cite:
@techreport{bartel2020causal,
author = {Bartel, Holger},
title = {Causal Analysis -- With an Application to Insurance Ratings},
year = {2020},
doi = {10.13140/RG.2.2.31524.83848}
}
Contributing
Contributions are welcome! Please open an issue or a pull request. See docs/contributing.md for the development setup, and the releases for the change history.
Star history
License and contact
Causing is free software written in Python 3 and available under the MIT license. It is developed by RealRate, an AI rating agency aiming to re-invent the rating market by using AI, interpretability, and avoiding any conflict of interest.
Dr. Holger Bartel — [email protected] — drbartel.com
関連プロジェクトを探す
読み込み中…