数据集因果分析工具 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

写给大忙人看的C++

写给大忙人看的C++

【美】Brian Overland(布莱恩.奥弗兰德) / 卢涛、李颖 / 电子工业出版社 / 2015-8 / 109.00

《写给大忙人看的C++》全面介绍了C++语言知识,既提供了学习C++语言最新功能的捷径,也为快速找到特定问题的答案提供了便利。《写给大忙人看的C++》简明地描述了C++核心语言和标准库中几乎所有的函数、对象和运算符,一目了然地显示了语法、结构和重要函数的信息,内容组织形式便于快速查找信息。《写给大忙人看的C++》精选了实用的例子来深入地讲解概念,还提供了富有挑战性的练习及参考答案,便于读者举一反三......一起来看看 《写给大忙人看的C++》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具