数据集因果分析工具 Causality

码农软件 · 软件分类 · 常用工具包 · 2019-08-14 05:58:35

软件介绍

Causality 是一款数据集因果分析工具。

安装

如果有 pip,只需运行:

pip install causality

因果推论

因果关系模块将包含用于推断因果DAG的各种算法。

要在数据集上运行图形搜索,可以使用类似的算法(以IC *为例): 

import numpy
import pandas as pd

from causality.inference.search import IC
from causality.inference.independence_tests import RobustRegressionTest

# generate some toy data:
SIZE = 2000
x1 = numpy.random.normal(size=SIZE)
x2 = x1 + numpy.random.normal(size=SIZE)
x3 = x1 + numpy.random.normal(size=SIZE)
x4 = x2 + x3 + numpy.random.normal(size=SIZE)
x5 = x4 + numpy.random.normal(size=SIZE)

# load the data into a dataframe:
X = pd.DataFrame({'x1' : x1, 'x2' : x2, 'x3' : x3, 'x4' : x4, 'x5' : x5})

# define the variable types: 'c' is 'continuous'.  The variables defined here
# are the ones the search is performed over  -- NOT all the variables defined
# in the data frame.
variable_types = {'x1' : 'c', 'x2' : 'c', 'x3' : 'c', 'x4' : 'c', 'x5' : 'c'}

# run the search
ic_algorithm = IC(RobustRegressionTest, X, variable_types)
graph = ic_algorithm.search()

现在,我们推断图存储在图中。 在此图中,每个变量是一个节点(从DataFrame列命名),每个edge表示不能通过对搜索指定的变量进行调整来消除的节点之间的统计相关性。 如果edge可以用可用数据定向,则arrowhead在'arrows'中指示。 如果edge也满足用于真实因果的局部标准,则marked=True。 如果我们从搜索的结果打印edges,我们可以看到哪些edges是定向的,并且满足真正因果的局部标准:

>>> graph.edges(data=True)
[('x2', 'x1', {'arrows': [], 'marked': False}), 
 ('x2', 'x4', {'arrows': ['x4'], 'marked': False}), 
 ('x3', 'x1', {'arrows': [], 'marked': False}), 
 ('x3', 'x4', {'arrows': ['x4'], 'marked': False}), 
 ('x4', 'x5', {'arrows': ['x5'], 'marked': True})]

我们可以看到从'x2'到'x4','x3'到'x4'和'x4'到'x5'的edges都朝向每对的第二个。 此外,我们看到从'x4'到'x5'的edge满足真正因果关系的局部标准。 这与Pearl(2000)中figure 2.3(d)中给出的结构相符。

本文地址:https://codercto.com/soft/d/12316.html

Viral Loop

Viral Loop

Adam L. Penenberg / Tantor Media / 2009-10-27 / USD 34.99

From Google to Facebook, a respected journalist delves into how a "viral loop" can make an online business a success.一起来看看 《Viral Loop》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

MD5 加密
MD5 加密

MD5 加密工具

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试