Add ChiMerge constraint mode#158
Merged
Secbone merged 3 commits intoApr 13, 2026
Merged
Conversation
Secbone
approved these changes
Apr 10, 2026
5d6d4c9 to
a17f175
Compare
Member
|
Thanks for the great contribution! The feature looks solid and the core logic is correct. We've just merged some pandas 3.x compatibility fixes to master (#159), which conflict with the git fetch upstream
git rebase upstream/master
# resolve conflicts, drop impute.py changes
git push --force-with-leaseOnce CI is green after the rebase, we'll merge this. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
这个 PR 为 ChiMerge 增加了一个兼容式新参数 constraint_mode。
Fixes #12
若在fit中选择‘chi’, 且同时设置min_sample参数和n_bins参数,ChiMerge的逻辑:在满足其中一个条件后就break

例如设置参数n_bins = 5, min_samples=0.04(1.原意是希望分箱结果同时满足两个条件;2.此参数设置是合法且可行的),分箱会出现以下情况(以下图片的模拟数据集来源 https://www.kaggle.com/competitions/gmsc-thebridge-dsft2109/data ):
1.先满足 min_samples,此时虽然每箱样本占比都足够大,但箱数仍然大于 n_bins,算法却提前停止。

2.先满足 n_bins,此时箱数已经不超过目标,但仍存在极小箱,算法也会提前停止。

此PR新增constraint_mode,将这个参数从 Python 包装层一路透传到了 Rust 的 ChiMerge 核心逻辑,并在 all 模式下保留了 empty_separate=True 的现有语义。默认 constraint_mode='any' 保持旧行为不变,也就是 n_bins、min_samples、min_threshold 任一条件满足就停止;新增的 constraint_mode='all' 则把 n_bins 和 min_samples 当作硬约束,只有“箱数 <= n_bins”且“每个普通箱样本数/占比 >= min_samples”同时满足时才停止。

改动后同参数同特征的分箱结果如图所示:

测试了修改的部分
