Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get error in refutation process ValueError: No group keys passed! #1028

Closed
stvgz opened this issue Sep 3, 2023 · 6 comments · Fixed by #1159
Closed

Get error in refutation process ValueError: No group keys passed! #1028

stvgz opened this issue Sep 3, 2023 · 6 comments · Fixed by #1159
Labels
bug Something isn't working

Comments

@stvgz
Copy link

stvgz commented Sep 3, 2023

Describe the bug
Get error in refutation

Steps to reproduce the behavior

Very common steps
Read data
earnings_data = pd.read_csv(r'./data/ml_earnings.csv')

Define graph and model

`# Construct the graph (the graph is constant for all iterations)
nodes = ['took_a_course', 'earnings', 'age']
edges = [
('took_a_course', 'earnings'),
('age', 'took_a_course'),
('age', 'earnings')
]

Generate the GML graph

gml_string = 'graph [directed 1\n'

for node in nodes:
gml_string += f'\tnode [id "{node}" label "{node}"]\n'

for edge in edges:
gml_string += f'\tedge [source "{edge[0]}" target "{edge[1]}"]\n'

gml_string += ']'`

# Instantiate the CausalModel model = CausalModel( data=earnings_data, treatment='took_a_course', outcome='earnings', graph=gml_string )

estimate
# Get estimate (Matching) estimate = model.estimate_effect( identified_estimand=estimand, method_name='backdoor.distance_matching', target_units='ate', method_params={'distance_metric': 'minkowski', 'p': 2})

Refute
refutation = model.refute_estimate( estimand=estimand, estimate=estimate, method_name= "random_common_cause", # method_name = 'add_unobserved_common_cause' )

Error I got

`---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[23], line 1
----> 1 refutation = model.refute_estimate(
2 estimand=estimand,
3 estimate=estimate,
4 method_name= "random_common_cause",
5 # method_name = 'add_unobserved_common_cause'
6 )

File ~/opt/anaconda3/envs/causal/lib/python3.9/site-packages/dowhy/causal_model.py:434, in CausalModel.refute_estimate(self, estimand, estimate, method_name, show_progress_bar, **kwargs)
431 refuter_class = causal_refuters.get_class_object(method_name)
433 refuter = refuter_class(self._data, identified_estimand=estimand, estimate=estimate, **kwargs)
--> 434 res = refuter.refute_estimate(show_progress_bar)
435 return res

File ~/opt/anaconda3/envs/causal/lib/python3.9/site-packages/dowhy/causal_refuters/random_common_cause.py:45, in RandomCommonCause.refute_estimate(self, show_progress_bar)
44 def refute_estimate(self, show_progress_bar=False):
---> 45 refute = refute_random_common_cause(
46 self._data,
47 self._target_estimand,
48 self._estimate,
49 self._num_simulations,
50 self._random_state,
51 show_progress_bar,
...
--> 917 raise ValueError("No group keys passed!")
918 elif len(groupings) == 0:
919 groupings.append(Grouping(Index([], dtype="int"), np.array([], dtype=np.intp)))

ValueError: No group keys passed!`

This can also include a verbatim copy of outputs, or screenshots.

Expected behavior
A clear and concise description of what you expected to happen.

Version information:

  • mac os
  • python '3.9.16 (main, May 15 2023, 18:51:40) \n[Clang 14.0.6 ]'
  • DoWhy version 0.9.0 & 0.10.0 shows same result

Additional context

Example from book Causal Inference and Discovery

@stvgz stvgz added the bug Something isn't working label Sep 3, 2023
@galkampel
Copy link

Hi @stvgz ,
I had the same issue.
I was able to solve the problem by uninstalling the DoWhy (installation with pip), and reinstalling using
conda (version 0.8).
conda install -c conda-forge dowhy
Hope it helps!

@brady-shaffer
Copy link

@stvgz I'm experiencing the same issue. Tried on:
Windows 10 Enterprise LTSC, Python 3.11.3, dowhy 0.11.1
Linux (Ubuntu 22.04.4 LTS), Python 3.10.12, dowhy 0.11.1

Exact same error as the traceback above after calling the refute_estimate method using identical parameters.

@WeimusT
Copy link

WeimusT commented Apr 11, 2024

@stvgz I have the same error and it is from the same example from the book Causal Inference and Discovery in Python. Pip uninstall dowhy and conda install did not work for me @galkampel. I am on MacOS Sonoma 14.3, Python 3.10.14, dowhy 0.11.1

Updates:
This error is only seen using the random_common_cause refuter. The placebo_treatment_refuter and data_subset_refuter work fine.

@bloebp
Copy link
Member

bloebp commented Apr 11, 2024

@amit-sharma

@amit-sharma
Copy link
Member

thanks for tagging @bloebp Let me take a look at this.

@HuayuChen2004
Copy link

Hi @stvgz
I experienced the same issue and found that the code worked after changing the version of dowhy to 0.8, by running

pip uninstall dowhy

and

pip install dowhy==0.8

then I restarted the kernel and it worked out.
Hope this can help you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants