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_tmlegain() ValueError: Bin edges must be unique #771

Closed
craftsliu opened this issue May 6, 2024 · 1 comment · Fixed by #773
Closed

get_tmlegain() ValueError: Bin edges must be unique #771

craftsliu opened this issue May 6, 2024 · 1 comment · Fixed by #773
Labels
bug Something isn't working

Comments

@craftsliu
Copy link


ValueError Traceback (most recent call last)
--> 324 plot_tmlegain(pred_df, inference_col, outcome_col=y_col,
325 treatment_col=treatment_col, p_col=p_col)
326

~/anaconda3/envs/myenv/lib/python3.8/site-packages/causalml/metrics/visualize.py in plot_tmlegain(df, inference_col, learner, outcome_col, treatment_col, p_col, n_segment, cv, calibrate_propensity, ci, figsize)
656 ci (bool, optional): whether return confidence intervals for ATE or not
657 """
--> 658 plot_df = get_tmlegain(
659 df,
660 learner=learner,

~/anaconda3/envs/myenv/lib/python3.8/site-packages/causalml/metrics/visualize.py in get_tmlegain(df, inference_col, learner, outcome_col, treatment_col, p_col, n_segment, cv, calibrate_propensity, ci)
341 treatment=df[treatment_col],
342 y=df[outcome_col],
--> 343 segment=pd.qcut(df[col], n_segment, labels=False),
344 )
345 lift_model = [0.0] * (n_segment + 1)

~/anaconda3/envs/myenv/lib/python3.8/site-packages/pandas/core/reshape/tile.py in qcut(x, q, labels, retbins, precision, duplicates)
370 quantiles = q
371 bins = algos.quantile(x, quantiles)
--> 372 fac, bins = _bins_to_cuts(
373 x,
374 bins,

~/anaconda3/envs/myenv/lib/python3.8/site-packages/pandas/core/reshape/tile.py in _bins_to_cuts(x, bins, right, labels, precision, include_lowest, dtype, duplicates, ordered)
411 if len(unique_bins) < len(bins) and len(bins) != 2:
412 if duplicates == "raise":
--> 413 raise ValueError(
414 f"Bin edges must be unique: {repr(bins)}.\n"
415 f"You can drop duplicate edges by setting the 'duplicates' kwarg"

ValueError: Bin edges must be unique: array([-0.08210021, 0. , 0. , 0. , 0. ,
0.07284003]).
You can drop duplicate edges by setting the 'duplicates' kwarg

Environment (please complete the following information):

  • OS: [Linux]
  • Python Version: [e.g. 3.8.19]
  • Versions of Major Dependencies (pandas, scikit-learn, cython): [e.g. pandas==1.3.5, scikit-learn==1.0.2, cython==0.29.34]
@craftsliu craftsliu added the bug Something isn't working label May 6, 2024
@craftsliu
Copy link
Author

use pd.qcut(df[col], n_segment, labels=False, duplicates='drop') to solve thie problem?

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.

1 participant