OptimalBinning2D not working with numerical and categorical predictor
See original GitHub issueHello, I enjoy your package very much as it makes feature engineering, in some cases, much simpler. I suspect it is a bug, and you probably didn’t think of 2D binning using categorical predictors. I cannot provide you the data, but I hope it is clear.
from optbinning import OptimalBinning2D
col1, col2 = "NUMERICAL_32", "CATEGORICAL_10"
col_target = "TARGET"
optb = OptimalBinning2D(name_x=col1, name_y=col2, dtype_x="numerical", dtype_y="categorical", solver="cp")
x = data[col1].values
y = data[col2].values
z = data[col_target]
optb.fit(x, y, z)
optb.binning_table.build(show_bin_xy=True)
ifeat_woe = optb.transform(x, y, metric="woe")
I am getting following error.
Traceback (most recent call last):
File "/Users/danielherman/Documents/projects/ifeat/ifeat_optbinning.py", line 43, in <module>
ifeat_woe = optb.transform(x, y, metric="woe")
File "/Users/danielherman/Documents/projects/ifeat/env/lib/python3.9/site-packages/optbinning/binning/multidimensional/binning_2d.py", line 551, in transform
return transform_binary_target(
File "/Users/danielherman/Documents/projects/ifeat/env/lib/python3.9/site-packages/optbinning/binning/multidimensional/transformations_2d.py", line 123, in transform_binary_target
bins_str = bin_xy_str_format(dtype_x, dtype_y, splits_x, splits_y,
File "/Users/danielherman/Documents/projects/ifeat/env/lib/python3.9/site-packages/optbinning/binning/multidimensional/binning_statistics_2d.py", line 72, in bin_xy_str_format
_by = _bin_fmt_categorical(by, categories_y)
File "/Users/danielherman/Documents/projects/ifeat/env/lib/python3.9/site-packages/optbinning/binning/multidimensional/binning_statistics_2d.py", line 42, in _bin_fmt_categorical
n_categories = len(categories)
TypeError: object of type 'NoneType' has no len()
I am also using the last available version 0.15.1.
Will you add the support of 2D binning with numerical+categorical predictors and categorical+categorical predictors?
Issue Analytics
- State:
- Created a year ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
guillermo-navas-palencia/optbinning: Optimal binning - GitHub
OptBinning is a library written in Python implementing a rigorous and flexible mathematical programming formulation to solve the optimal binning problem for ...
Read more >Tutorial: Binning process with sklearn Pipeline — optbinning ...
Instantiate a BinningProcess object class with variable names and the list of numerical variables to be considered categorical. Create pipeline object by ...
Read more >Using numerical and categorical variables together
We will separate categorical and numerical variables using their data types ... Besides, we use handle_unknown="ignore" to solve the potential issues due to ......
Read more >Optimal binning methods for categorical variables
I'm running a multinomial logit to predict the outcome of a categoric response variable ...
Read more >Dealing with Categorical Variables in Machine Learning
Real-world data issues and machine learning model. Image by author ... Data set comprises of both numerical and categorical variables.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It didn’t solve the issue, I will try to build reproducible code today.
Perfect. The code must be improved, though.