uber / causalml

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

OneHotEncoder UnboundLocalError #764

Closed craftsliu closed 2 months ago

craftsliu commented 2 months ago

UnboundLocalError Traceback (most recent call last) /tmp/ipykernel_3893757/880346473.py in () 2 p_model = ElasticNetPropensityModel() 3 ohe = OneHotEncoder(min_obs=df.shape[0] * 0.01) ----> 4 X_cat = ohe.fit_transform(df_matched[ENCODING_COLS]).todense() 5 X = np.hstack([df_matched[PROPENSITY_FEATURES].values, X_cat]) 6

~/anaconda3/envs/myenv/lib/python3.8/site-packages/causalml/features.py in fit_transform(self, X, y) 223 self.label_encoder.fit(X) 224 --> 225 return self.transform(X) 226 227

~/anaconda3/envs/myenv/lib/python3.8/site-packages/causalml/features.py in transform(self, X) 203 X_new = X_col 204 else: --> 205 X_new = sparse.hstack((X_new, X_col)) 206 207 logger.debug(

UnboundLocalError: local variable 'X_new' referenced before assignment Environment (please complete the following information):

Additional context Add any other context about the problem here.

craftsliu commented 2 months ago

image when i ! = 0, it will raise the problems

paullo0106 commented 2 months ago

@craftsliu thanks for reporting. While I see an opportunity to improve our code to capture cases like this, can I ask where does your df or df_matched come from? in case it's a public data source that i can easily reproduce your error.