A package for causal discovery and causal inference algorithms
Project description
MagPy: Causal Discovery and Effect Estimation Framework
MagPy is a Python framework for causal discovery and effect estimation, aimed at uncovering causal relationships in observational data and estimate the impact of interventinos/counterfactuals.
Project Scope
The primary focus of MagPy is causal discovery, which involves:
- Learning the structure of causal graphs from observational data
- Handling mixed data types (continuous, categorical, binary)
- Implementing constraint-based and score-based algorithms
- Providing tools for causal inference and intervention analysis
Installation
git clone https://github.com/ergodic-ai/magpy.git
cd magpy
pip install .
or
pip install git+https://github.com/ergodic-ai/magpy.git
Main Packages and Usage
1. AStarSearch
The AStarSearch class implements the A* search algorithm for Bayesian network structure learning.
import pandas as pd
from magpy.search.astar import AStarSearch, bic_score_node
data: pd.DataFrame = ...
astar = AStarSearch(data)
astar.run_scoring(func=bic_score_node, parallel=True)
result = astar.search()
Key features:
- Custom scoring functions
- Parallel processing
- Constraint-based search with super_graph and include_graph
2. Oracles
We are introducing a variety of conditional independence tests - oracles.
As an example, the MixedDataOracle class handles conditional independence testing for mixed data types.
from magpy.oracles.mixed import MixedDataOracle
oracle = MixedDataOracle(data, threshold=0.05)
independent = oracle(x, y, Z)
3. PC Skeleton Algorithm
The pc_skeleton function implements the PC algorithm for learning the skeleton of a causal graph.
from magpy.search.pcskeleton import pc_skeleton
from magpy.oracles.mixed import MixedDataOracle
import pandas
data: pandas.DataFrame = ...
nodes = list(data.columns)
oracle = MixedDataOracle(data, threshold=0.05)
skeleton, sepsets = pc_skeleton(oracle, nodes)
3. Quick Start
For continuous data:
import pandas as pd
from magpy.search.astar import AStarSearch, bic_score_node
data = pd.read_csv('your_data.csv')
astar = AStarSearch(data)
astar.run_scoring(func=bic_score_node, parallel=True)
result = astar.search()
import networkx as nx
import matplotlib.pyplot as plt
G = nx.from_pandas_adjacency(result, create_using=nx.DiGraph)
nx.draw(G, with_labels=True)plt.show()
For categorical data, see the sf.ipynb notebook.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file causal_magpy-0.1.0-py3-none-any.whl.
File metadata
- Download URL: causal_magpy-0.1.0-py3-none-any.whl
- Upload date:
- Size: 29.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
22288274a4ae926962bb2e5f845e2163409fdd51a65f617652cb7524409fdac3
|
|
| MD5 |
51e8102d71bd6331a99da3a30015352e
|
|
| BLAKE2b-256 |
af14bf4b777d0dd768c51a142bfe9dd40d8c68ab6b0461bbe05f97f28d30a632
|