Comments (8)
The column conversion needs to happen before calling the assignment and fit, otherwise the variables are expected to be integers, but are strings. I had similar issues before due to integer column names. So, maybe just change:
data_pd.columns = [i for i in range(len(data_pd.columns))] #define the columns as integer
to
data_pd.columns = [str(i) for i in range(len(data_pd.columns))]
But you also need to make sure that the node names in the graph are strings of integers instead of raw integers themselves.
from dowhy.
Might be an issue with the variable names in the dataframe. Can you try the following after loading/creating the data:
data_pd.columns = [str(col) for col in data_pd.columns]
from dowhy.
Thnks, I tried but now I had as error:
AssertionError: 2 must be list, set or str. Got <class 'int'> instead!
the type of variable names in the dataframe is:
Index(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10'], dtype='object')
<class 'pandas.core.indexes.base.Index'>
so I don't know if this is the problem, many tks
from dowhy.
Ok, do you think you can provide a small example snippet to reproduce this (you probably don't need the streamlit context here)? I can take a closer look then.
from dowhy.
Ok , thanks
I had a nx.graph (the nodes are int) I compute scm:
scm = gcm.StructuralCausalModel(st.session_state["pc_graph_nx"])
then for assigning causal mechanism I run:
data_pd = pd.DataFrame(data_agg) #dataframe of my data
data_pd.columns = [i for i in range(len(data_pd.columns))] #define the columns as integer
data_pd = check_and_convert_categorical(data_pd, threshold=2) #use a function to get categorical variables
auto_assignment_summary = gcm.auto.assign_causal_mechanisms(
scm, data_pd, override_models=True, quality=gcm.auto.AssignmentQuality.GOOD
)
gcm.fit(scm, data_pd)
st.text(auto_assignment_summary) #until now no problem
def convert_nodes_to_str(nx_graph): #convert nodes in string
mapping = {node: str(node) for node in nx_graph.nodes}
nx_graph = nx.relabel_nodes(nx_graph, mapping)
return nx_graph
data_pd.columns = [str(col) for col in data_pd.columns] #as suggested
and finally the code (in streamlit):
pc_graph_nx=convert_nodes_to_str(st.session_state["pc_graph_nx"])
print(pc_graph_nx.nodes)
result = falsify_graph((st.session_state["pc_graph_nx"]), data_pd, plot_histogram=False, suggestions=True, n_permutations=100)
st.text(result)
with the error:
AssertionError: 1 must be list, set or str. Got <class 'int'> instead!
Traceback:
File "C:\Users\11612880\Anaconda3\envs\causal\lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 600, in run_script
exec(code, module.dict)
File "C:\Users\11612880\Desktop\Causal-Discovery-PoC\pages\9_📊 SCM.py", line 167, in
result = falsify_graph((st.session_state["pc_graph_nx"]), data_pd, plot_histogram=False, suggestions=True, n_permutations=100)
File "C:\Users\11612880\Anaconda3\envs\causal\lib\site-packages\dowhy\gcm\falsify.py", line 618, in falsify_graph
summary_given = run_validations(
File "C:\Users\11612880\Anaconda3\envs\causal\lib\site-packages\dowhy\gcm\falsify.py", line 412, in run_validations
m_summary = m(causal_graph=causal_graph)
File "C:\Users\11612880\Anaconda3\envs\causal\lib\site-packages\dowhy\gcm\falsify.py", line 138, in validate_lmc
if not (node, non_desc, parents) in p_values_memory:
File "C:\Users\11612880\Anaconda3\envs\causal\lib\site-packages\dowhy\gcm\falsify.py", line 89, in contains
X, Y = (_to_frozenset(i) for i in item[:2])
File "C:\Users\11612880\Anaconda3\envs\causal\lib\site-packages\dowhy\gcm\falsify.py", line 89, in
X, Y = (_to_frozenset(i) for i in item[:2])
File "C:\Users\11612880\Anaconda3\envs\causal\lib\site-packages\dowhy\gcm\falsify.py", line 979, in _to_frozenset
assert (
any idea? thanks
from dowhy.
Now it works, thanks very appreciated
from dowhy.
This issue is stale because it has been open for 14 days with no activity.
from dowhy.
This issue was closed because it has been inactive for 7 days since being marked as stale.
from dowhy.
Related Issues (20)
- Does this package support non-English languages? HOT 3
- Question about Dummy Outcome Refuter HOT 2
- Inconsistency in the placebo_treatment_refuter when using estimate_effect of IV HOT 1
- numpy.dual is dropped but it still occurs in dowhy HOT 2
- NetworkXError: graph should be directed acyclic HOT 4
- Refutation & Overlap Error ("data_subset_refuter", "add_unobserved_common_cause", assess_support_and_overlap_overrule) HOT 2
- No Backdoor Path Available
- Clarification on how to use gcm properly for confounders adjustment HOT 5
- Can you provide code demo for each function? HOT 2
- How is propensity score matching implemented? HOT 2
- Interpreting mean while using logistic regression to estimate causal effect. HOT 1
- model.estimate_effect and model.refute_astimate throws 'A column-vector y was passed ...' error
- RuntimeWarning: divide by zero encountered in divide when using evaluate_causal_model HOT 3
- Auto assign_causal_mechanisms is taking so much time in gcm HOT 11
- Remove use of CausalModel from test files and notebooks
- Is there a way to work with a structural causal model where nodes have multiple values? For use in root cause analysis. HOT 8
- graph should be directed acyclic HOT 1
- dowhy replication issue and output discrepancy with statsmodels
- how to show summary stats (R squared, p value, F stat) from causal estimate
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dowhy.