数据集因果分析工具 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://www.codercto.com/soft/d/12316.html

算法导论(原书第3版)

算法导论(原书第3版)

Thomas H.Cormen、Charles E.Leiserson、Ronald L.Rivest、Clifford Stein / 殷建平、徐云、王刚、刘晓光、苏明、邹恒明、王宏志 / 机械工业出版社 / 2012-12 / 128.00元

在有关算法的书中,有一些叙述非常严谨,但不够全面;另一些涉及了大量的题材,但又缺乏严谨性。本书将严谨性和全面性融为一体,深入讨论各类算法,并着力使这些算法的设计和分析能为各个层次的读者接受。全书各章自成体系,可以作为独立的学习单元;算法以英语和伪代码的形式描述,具备初步程序设计经验的人就能看懂;说明和解释力求浅显易懂,不失深度和数学严谨性。 全书选材经典、内容丰富、结构合理、逻辑清晰,对本科......一起来看看 《算法导论(原书第3版)》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

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

正则表达式在线测试

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具