uber / causalml

Uplift modeling and causal inference with machine learning algorithms
Other
4.87k stars 756 forks source link

when the example jupyter notebook run, it raises an error #741

Closed tjefferson closed 3 months ago

tjefferson commented 4 months ago

Describe the bug A clear and concise description of what the bug is. notebook:https://github.com/uber/causalml/blob/master/docs/examples/meta_learners_with_synthetic_data.ipynb

error:


TypeError Traceback (most recent call last) Cell In[22], line 2 1 #distribution plot for signle simulation of Training ----> 2 distr_plot_single_sim(train_preds, kind='kde', linewidth=2, bw_method=0.5, 3 drop_learners=['S Learner (LR)',' S Learner (XGB)'])

File ~/miniconda3/lib/python3.11/site-packages/causalml/dataset/synthetic.py:229, in distr_plot_single_sim(synthetic_preds, kind, drop_learners, bins, histtype, alpha, linewidth, bw_method) 227 # deleted generated data and assign actual value 228 del preds_for_plot[KEY_GENERATED_DATA] --> 229 global_lower = np.percentile(np.hstack(preds_for_plot.values()), 1) 230 global_upper = np.percentile(np.hstack(preds_for_plot.values()), 99) 231 learners = list(preds_for_plot.keys())

File ~/miniconda3/lib/python3.11/site-packages/numpy/core/shape_base.py:216, in _vhstack_dispatcher(tup, dtype, casting) 215 def _vhstack_dispatcher(tup, *, dtype=None, casting=None): --> 216 return _arrays_for_stack_dispatcher(tup)

File ~/miniconda3/lib/python3.11/site-packages/numpy/core/shape_base.py:209, in _arrays_for_stack_dispatcher(arrays) 207 def _arrays_for_stack_dispatcher(arrays): 208 if not hasattr(arrays, "getitem"): --> 209 raise TypeError('arrays to stack must be passed as a "sequence" type ' 210 'such as list or tuple.') 212 return tuple(arrays)

TypeError: arrays to stack must be passed as a "sequence" type such as list or tuple.

To Reproduce Steps to reproduce the behavior:

runs the notebook

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

no error, and show the plot

Screenshots If applicable, add screenshots to help explain your problem.

image

Environment (please complete the following information):

Additional context Add any other context about the problem here.

jeongyoonlee commented 3 months ago

Thanks for filing the issue, @tjefferson.

I reproduced it and submitted a fix (#750). It was because numpy>=1.16 deprecated the support for non-sequence iterables, e.g., dict.values() in this case. Once #750 is merged, it should work.