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

无处不在的算法

无处不在的算法

[德]贝特霍尔德·弗金、赫尔穆特·阿尔特 / 机械工业出版社 / 2018-1-1

本书以简单易懂的写作风格,通过解决现实世界常见的问题来介绍各种算法技术,揭示了算法的设计与分析思想。全书共有41章,分为四大部分,图文并茂,把各种算法的核心思想讲得浅显易懂。本书可作为高等院校算法相关课程的本科生教材,也可作为研究人员、专业技术人员的常备参考书。一起来看看 《无处不在的算法》 这本书的介绍吧!

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具