py-why / py-why/EconML

can't use bootstrap inference with xlearner

Open
#333 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Jupyter Notebook
Stars
4.8k
Forks
827
PR merge metrics
No merged PRs in 30d

Description

I'm trying to fit x_learner and get CI. I can fit it without inference without error, but when I put BootstrapInference, it give the following error.
Did I miss anything?

X_learner.fit(df_avg.outcome, (df_avg.assignment=='treatment').astype(int), df_avg[heteX],
inference= BootstrapInference(n_bootstrap_samples=10,n_jobs=-1))


Empty Traceback (most recent call last)
~\AppData\Roaming\Python\Python36\site-packages\joblib\parallel.py in dispatch_one_batch(self, iterator)
807 try:
--> 808 tasks = self._ready_batches.get(block=False)
809 except queue.Empty:

~\Anaconda3\lib\queue.py in get(self, block, timeout)
160 if not self._qsize():
--> 161 raise Empty
162 elif timeout is None:

Empty:

During handling of the above exception, another exception occurred:

KeyError Traceback (most recent call last)
in ()
16 df_avg2 = df_avg.dropna()
17 X_learner.fit(df_avg2.booking_value_usd2, (df_avg2.assignment=='treatment').astype(int), df_avg2[heteX],
---> 18 inference='bootstrap')#BootstrapInference(n_bootstrap_samples=10,n_jobs=-1))
19
20

~\AppData\Roaming\Python\Python36\site-packages\econml\cate_estimator.py in call(self, Y, T, inference, *args, **kwargs)
90 if inference is not None:
91 # NOTE: we call inference fit after calling the main fit method
---> 92 inference.fit(self, Y, T, *args, **kwargs)
93 self._inference = inference
94 return self

~\AppData\Roaming\Python\Python36\site-packages\econml\inference.py in fit(self, estimator, *args, **kwargs)
49 def fit(self, estimator, *args, **kwargs):
50 est = BootstrapEstimator(estimator, self._n_bootstrap_samples, self._n_jobs, compute_means=False)
---> 51 est.fit(*args, **kwargs)
52 self._est = est
53

~\AppData\Roaming\Python\Python36\site-packages\econml\bootstrap.py in fit(self, *args, **named_args)
75 *[convertArg(arg, inds) for arg in args],
76 **{arg: convertArg(named_args[arg], inds) for arg in named_args})
---> 77 for obj, inds in zip(self._instances, indices)
78 )
79 return self

~\AppData\Roaming\Python\Python36\site-packages\joblib\parallel.py in call(self, iterable)
1027 # remaining jobs.
1028 self._iterating = False
-> 1029 if self.dispatch_one_batch(iterator):
1030 self._iterating = self._original_iterator is not None
1031

~\AppData\Roaming\Python\Python36\site-packages\joblib\parallel.py in dispatch_one_batch(self, iterator)
817 big_batch_size = batch_size * n_jobs
818
--> 819 islice = list(itertools.islice(iterator, big_batch_size))
820 if len(islice) == 0:
821 return False

~\AppData\Roaming\Python\Python36\site-packages\econml\bootstrap.py in (.0)
75 *[convertArg(arg, inds) for arg in args],
76 **{arg: convertArg(named_args[arg], inds) for arg in named_args})
---> 77 for obj, inds in zip(self._instances, indices)
78 )
79 return self

~\AppData\Roaming\Python\Python36\site-packages\econml\bootstrap.py in (.0)
73 self._instances = Parallel(n_jobs=self._n_jobs, prefer='threads', verbose=3)(
74 delayed(fit)(obj,
---> 75 *[convertArg(arg, inds) for arg in args],
76 **{arg: convertArg(named_args[arg], inds) for arg in named_args})
77 for obj, inds in zip(self._instances, indices)

~\AppData\Roaming\Python\Python36\site-packages\econml\bootstrap.py in convertArg(arg, inds)
70
71 def convertArg(arg, inds):
---> 72 return arg[inds] if arg is not None else None
73 self._instances = Parallel(n_jobs=self._n_jobs, prefer='threads', verbose=3)(
74 delayed(fit)(obj,

~\AppData\Roaming\Python\Python36\site-packages\pandas\core\series.py in getitem(self, key)
906 return self._get_values(key)
907
--> 908 return self._get_with(key)
909
910 def _get_with(self, key):

~\AppData\Roaming\Python\Python36\site-packages\pandas\core\series.py in _get_with(self, key)
941 # (i.e. self.iloc) or label-based (i.e. self.loc)
942 if not self.index._should_fallback_to_positional():
--> 943 return self.loc[key]
944 else:
945 return self.iloc[key]

~\AppData\Roaming\Python\Python36\site-packages\pandas\core\indexing.py in getitem(self, key)
877
878 maybe_callable = com.apply_if_callable(key, self.obj)
--> 879 return self._getitem_axis(maybe_callable, axis=axis)
880
881 def _is_scalar_access(self, key: Tuple):

~\AppData\Roaming\Python\Python36\site-packages\pandas\core\indexing.py in _getitem_axis(self, key, axis)
1097 raise ValueError("Cannot index with multidimensional key")
1098
-> 1099 return self._getitem_iterable(key, axis=axis)
1100
1101 # nested tuple slicing

~\AppData\Roaming\Python\Python36\site-packages\pandas\core\indexing.py in _getitem_iterable(self, key, axis)
1035
1036 # A collection of keys
-> 1037 keyarr, indexer = self._get_listlike_indexer(key, axis, raise_missing=False)
1038 return self.obj._reindex_with_indexers(
1039 {axis: [keyarr, indexer]}, copy=True, allow_dups=True

~\AppData\Roaming\Python\Python36\site-packages\pandas\core\indexing.py in _get_listlike_indexer(self, key, axis, raise_missing)
1252 keyarr, indexer, new_indexer = ax._reindex_non_unique(keyarr)
1253
-> 1254 self._validate_read_indexer(keyarr, indexer, axis, raise_missing=raise_missing)
1255 return keyarr, indexer
1256

~\AppData\Roaming\Python\Python36\site-packages\pandas\core\indexing.py in _validate_read_indexer(self, key, indexer, axis, raise_missing)
1314 with option_context("display.max_seq_items", 10, "display.width", 80):
1315 raise KeyError(
-> 1316 "Passing list-likes to .loc or [] with any missing labels "
1317 "is no longer supported. "
1318 f"The following labels were missing: {not_found}. "

KeyError: "Passing list-likes to .loc or [] with any missing labels is no longer supported. The following labels were missing: Int64Index([45401], dtype='int64'). See https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#deprecate-loc-reindex-listlike"

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the reported X_learner BootstrapInference failure from the example in the issue, then inspect econml/bootstrap.py and econml/inference.py around bootstrap fitting and argument indexing. Check how the pandas Series is indexed during resampling and run the existing inference tests if available. Done means bootstrap inference completes for this X_learner input without the missing-label KeyError.

Written by the indexing model from the issue text.

Assessment

Tech stack
pandas, python
Domain
machine-learning
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.