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

使用bin_plot观察分箱时,不支持column为bool型 #123

Open
xujingyi0707 opened this issue Apr 23, 2023 · 0 comments
Open

使用bin_plot观察分箱时,不支持column为bool型 #123

xujingyi0707 opened this issue Apr 23, 2023 · 0 comments

Comments

@xujingyi0707
Copy link

设计评分卡时对分类型特征进行了onehot编码处理,保存为bool型。能够成功训练,分箱结果为A [[False], [True]]。
但是使用bin_plot画图时,提示不支持bool型:
from toad.plot import bin_plot
col = 'A'
bin_plot(c.transform(train_selected[[col,'label']], labels=True), x=col, target='label')

报错:

TypeError Traceback (most recent call last)
Cell In[22], line 3
1 from toad.plot import bin_plot
2 col = 'A'
----> 3 bin_plot(c.transform(train_selected[[col,'label']], labels=True), x=col, target='label')

File ~/miniconda3/envs/toad/lib/python3.8/site-packages/sklearn/utils/_set_output.py:140, in _wrap_method_output..wrapped(self, X, *args, **kwargs)
138 @wraps(f)
139 def wrapped(self, X, *args, **kwargs):
--> 140 data_to_wrap = f(self, X, *args, **kwargs)
141 if isinstance(data_to_wrap, tuple):
142 # only wrap the first output for cross decomposition
143 return (
144 _wrap_data_with_container(method, data_to_wrap[0], X, self),
145 *data_to_wrap[1:],
146 )

File ~/miniconda3/envs/toad/lib/python3.8/site-packages/toad/transform.py:93, in Transformer.transform(self, X, *args, **kwargs)
91 except Exception as e:
92 e.args += ('on column "{key}"'.format(key = key),)
---> 93 raise e
95 return res

File ~/miniconda3/envs/toad/lib/python3.8/site-packages/toad/transform.py:90, in Transformer.transform(self, X, *args, **kwargs)
88 if key in self.rules:
89 try:
---> 90 res[key] = self.transform_(self.rules[key], X[key], *args, **kwargs)
91 except Exception as e:
92 e.args += ('on column "{key}"'.format(key = key),)

File ~/miniconda3/envs/toad/lib/python3.8/site-packages/toad/transform.py:264, in Combiner.transform_(self, rule, X, labels, ellipsis, **kwargs)
261 bins = bin_by_splits(X, rule)
263 if labels:
--> 264 formated = self.format_bins(rule, index = True, ellipsis = ellipsis)
265 empty_mask = (bins == self.EMPTY_BIN)
266 bins = formated[bins]

File ~/miniconda3/envs/toad/lib/python3.8/site-packages/toad/utils/mixin.py:186, in BinsMixin.format_bins(self, bins, index, ellipsis)
184 l.append(keys)
185 else:
--> 186 label = ','.join(keys)
187 if ellipsis is not None:
188 label = label[:ellipsis] + '..' if len(label) > ellipsis else label

TypeError: ('sequence item 0: expected str instance, bool found', 'on column "A"')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant