본문 바로가기

Causal AI

[Library review] Causal discovery toolbox

반응형

 

https://fentechsolutions.github.io/CausalDiscoveryToolbox/html/tutorial_1.html#load-data

 

Basic Tutorial — Causal Discovery Toolbox 0.6.0 documentation

Loading a standard dataset using the cdt package is straightforward using the cdt.data module. In this tutorial, we are going to load the Sachs dataset. See also Sachs, K., Perez, O., Pe’er, D., Lauffenburger, D. A., & Nolan, G. P. (2005). Causal protein

fentechsolutions.github.io

 

 

 

 

import cdt
import networkx as nx
import seaborn as sns
cdt.SETTINGS.rpath = 'C:/Program Files/R/R-4.2.2/bin/Rscript'
 
 
 
 
data, graph  = cdt.data.load_dataset('sachs')
data

graph

 

glasso = cdt.independence.graph.Glasso()
skeleton = glasso.predict(data)
print(skeleton)

 

skeleton_matrix=nx.adjacency_matrix(skeleton).todense()
print(skeleton_matrix)
sns.heatmap(skeleton_matrix)

 

 

new_skeleton = cdt.utils.graph.remove_indirect_links(skeleton, alg='aracne')
new_skeleton_matrix = nx.adjacency_matrix(new_skeleton).todense()
print(new_skeleton_matrix)
sns.heatmap(new_skeleton_matrix)

 

 

model = cdt.causality.graph.GES()
output_graph = model.predict(data,new_skeleton)
output_graph_matrix = nx.adjacency_matrix(output_graph).todense()

 

print(output_graph_matrix)
sns.heatmap(output_graph_matrix)

 

 

nx.draw_networkx(output_graph, font_size=10, font_color='r')

 

 

 

 

반응형
LIST

'Causal AI' 카테고리의 다른 글

Why causal AI  (0) 2023.05.07
causal AI 란 무엇일까?  (0) 2023.05.05
Causal AI (Causal discovery and inference) open-source library  (0) 2023.02.07