You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This code crashed with the following error message
Traceback (mostrecentcalllast):
File"/home/code/projects/uplift/env/lib/python3.6/site-packages/sklearn/externals/joblib/externals/loky/process_executor.py", line418, in_process_workerr=call_item()
File"/home/code/projects/uplift/env/lib/python3.6/site-packages/sklearn/externals/joblib/externals/loky/process_executor.py", line272, in__call__returnself.fn(*self.args, **self.kwargs)
File"/home/code/projects/uplift/env/lib/python3.6/site-packages/sklearn/externals/joblib/_parallel_backends.py", line567, in__call__returnself.func(*args, **kwargs)
File"/home/code/projects/uplift/env/lib/python3.6/site-packages/sklearn/externals/joblib/parallel.py", line225, in__call__forfunc, args, kwargsinself.items]
File"/home/code/projects/uplift/env/lib/python3.6/site-packages/sklearn/externals/joblib/parallel.py", line225, in<listcomp>forfunc, args, kwargsinself.items]
File"/home/code/projects/uplift/env/lib/python3.6/site-packages/sklearn/model_selection/_validation.py", line528, in_fit_and_scoreestimator.fit(X_train, y_train, **fit_params)
File"/home/code/projects/uplift/env/lib/python3.6/site-packages/xgboost/sklearn.py", line703, infitmissing=self.missing, nthread=self.n_jobs)
File"/home/code/projects/uplift/env/lib/python3.6/site-packages/xgboost/core.py", line427, in__init__self.set_weight(weight)
File"/home/code/projects/uplift/env/lib/python3.6/site-packages/xgboost/core.py", line698, inset_weightself.set_float_info('weight', weight)
File"/home/code/projects/uplift/env/lib/python3.6/site-packages/xgboost/core.py", line592, inset_float_infoc_data=c_array(ctypes.c_float, data)
File"/home/code/projects/uplift/env/lib/python3.6/site-packages/xgboost/core.py", line219, inc_arrayreturn (ctype*len(values))(*values)
TypeError: objectoftype'float'hasnolen()
"""The above exception was the direct cause of the following exception:TypeError Traceback (most recent call last)~/projects/uplift/model.py in <module> 31 col_propensity='propensity', 32 col_outcome='Outcome')---> 33 train_df, test_df = model.estimate_cate_by_2_models() 34 # estimated_effect_df = model.estimate_recommendation_impact()~/projects/uplift/env/lib/python3.6/site-packages/causallift/causal_lift.py in estimate_cate_by_2_models(self, verbose) 194 enable_ipw=self.enable_ipw, 195 uplift_model_params=self.uplift_model_params,--> 196 cv=self.cv) 197 model_for_untreated = ModelForUntreated(train_df_, test_df_, 198 random_state=self.random_state,~/projects/uplift/env/lib/python3.6/site-packages/causallift/model_for_each.py in __init__(self, *args, **kwargs) 224 def __init__(self, *args, **kwargs): 225 kwargs.update(treatment_val=1.0)--> 226 super().__init__(*args, **kwargs) 227 228 ~/projects/uplift/env/lib/python3.6/site-packages/causallift/model_for_each.py in __init__(self, train_df_, test_df_, treatment_val, random_state, verbose, cols_features, col_treatment, col_outcome, col_propensity, col_recommendation, min_propensity, max_propensity, enable_ipw, uplift_model_params, cv) 101 params, cv=cv, return_train_score=False, n_jobs=-1) 102 --> 103 model.fit(X_train, y_train, sample_weight=sample_weight) 104 if verbose >= 3: 105 print('### Best parameters of the model trained using samples with observational Treatment: {} \n {}'.~/projects/uplift/env/lib/python3.6/site-packages/sklearn/model_selection/_search.py in fit(self, X, y, groups, **fit_params) 720 return results_container[0] 721 --> 722 self._run_search(evaluate_candidates) 723 724 results = results_container[0]~/projects/uplift/env/lib/python3.6/site-packages/sklearn/model_selection/_search.py in _run_search(self, evaluate_candidates) 1189 def _run_search(self, evaluate_candidates): 1190 """Searchallcandidatesinparam_grid"""-> 1191 evaluate_candidates(ParameterGrid(self.param_grid)) 1192 1193 ~/projects/uplift/env/lib/python3.6/site-packages/sklearn/model_selection/_search.py in evaluate_candidates(candidate_params) 709 for parameters, (train, test) 710 in product(candidate_params,--> 711 cv.split(X, y, groups))) 712 713 all_candidate_params.extend(candidate_params)~/projects/uplift/env/lib/python3.6/site-packages/sklearn/externals/joblib/parallel.py in __call__(self, iterable) 928 929 with self._backend.retrieval_context():--> 930 self.retrieve() 931 # Make sure that we get a last message telling us we are done 932 elapsed_time = time.time() - self._start_time~/projects/uplift/env/lib/python3.6/site-packages/sklearn/externals/joblib/parallel.py in retrieve(self) 831 try: 832 if getattr(self._backend, 'supports_timeout', False):--> 833 self._output.extend(job.get(timeout=self.timeout)) 834 else: 835 self._output.extend(job.get())~/projects/uplift/env/lib/python3.6/site-packages/sklearn/externals/joblib/_parallel_backends.py in wrap_future_result(future, timeout) 519 AsyncResults.get from multiprocessing."""520try:
-->521returnfuture.result(timeout=timeout)
522exceptLokyTimeoutError:
523raiseTimeoutError()
/usr/lib/python3.6/concurrent/futures/_base.pyinresult(self, timeout)
430raiseCancelledError()
431elifself._state==FINISHED:
-->432returnself.__get_result()
433else:
434raiseTimeoutError()
/usr/lib/python3.6/concurrent/futures/_base.pyin__get_result(self)
382def__get_result(self):
383ifself._exception:
-->384raiseself._exception385else:
386returnself._resultTypeError: objectoftype'float'hasnolen()
If I understand the document correctly, when the propensity is calculated beforehand, the flag enable_ipw is set to False. Assuming my object is initialized with the right parameters, I suspect that in line 76 in model_for_each module the sample_weight is defined as a float (1.0) while it should be a numpy array.
The text was updated successfully, but these errors were encountered:
Thank you for reporting the error.
Yes, sample_weight should be an array.
I fixed the error in v0.0.2.
To use the propensity computed beforehand, set enable_ipw True, and specify the column name of propensity with col_propensity (apparently 'likelihood' in your case).
If you set enable_ipw False, Inverse Probability Weighting is disabled.
To clarify, there are 3 ways to use CausalLift.
enable_ipw = True using propensity computed by CausalLift
As in CausalLift_example.ipynb
enable_ipw = True using propensity computed beforehand
Your case
enable_ipw = False
If the data is from A/B testing or Randomized Control Trial
I am using the example provided in https://colab.research.google.com/github/Minyus/causallift/blob/master/examples/CausalLift_example.ipynb. However I am trying to test a scenario where the propensity is computed beforehand. In my CasualLift I initialize the object using
This code crashed with the following error message
If I understand the document correctly, when the propensity is calculated beforehand, the flag enable_ipw is set to False. Assuming my object is initialized with the right parameters, I suspect that in line 76 in model_for_each module the sample_weight is defined as a float (1.0) while it should be a numpy array.
The text was updated successfully, but these errors were encountered: