Skip to content

Fix class weights in grid and randomized search - #3198

Closed
RAVasiliev wants to merge 4 commits into
catboost:masterfrom
RAVasiliev:codex/catboost-grid-search-class-weights
Closed

RAVasiliev wants to merge 4 commits into
catboost:masterfrom
RAVasiliev:codex/catboost-grid-search-class-weights

Conversation

@RAVasiliev

Copy link
Copy Markdown
Contributor

Fixes #2392.

Grid and randomized search reused the first candidate's class weights, so changing their order could change the result. This updates the weights for each candidate while keeping the quantized features cached. It also fixes the use_weights=false error when class weights are set. Weighted metrics remain the default.

Tested on CPU/macOS ARM64: all 28 new regression cases fail before the fix and pass after it. All 12 existing search tests pass too.

@RAVasiliev

Copy link
Copy Markdown
Contributor Author

The macOS build failed during conan install because it couldn't resolve center2.conan.io (log). This PR doesn't change the build scripts or dependencies, and the Linux and Windows jobs passed. Could you please rerun the failed job?

Comment thread catboost/python-package/ut/medium/test_search_class_weights.py Outdated
Comment thread catboost/python-package/ut/medium/test_search_class_weights.py Outdated
Comment thread catboost/python-package/ut/medium/test_search_class_weights.py Outdated
Comment thread catboost/python-package/ut/medium/test_search_class_weights.py Outdated
@RAVasiliev

Copy link
Copy Markdown
Contributor Author

Thanks, this is a better fit for these tests. Replaced the sklearn generator with generate_random_labeled_dataset and added type annotations to all three functions in 15bea17. All 28 updated cases pass with the fix and fail on unpatched CatBoost 1.2.10.

@robot-magpie

robot-magpie Bot commented Oct 3, 2026

Copy link
Copy Markdown

@andrey-khropov has imported your pull request. If you are a Yandex employee, you can view this diff.

@robot-magpie

robot-magpie Bot commented Oct 3, 2026

Copy link
Copy Markdown

✅ This pull request is being closed because it has been successfully merged into our internal monorepository.
Your changes will be pushed to this repository soon. Thank you for your contribution!

@robot-magpie robot-magpie Bot closed this Oct 3, 2026
robot-piglet pushed a commit that referenced this pull request Oct 3, 2026
Fixes #2392.

Grid and randomized search reused the first candidate's class weights, so changing their order could change the result. This updates the weights for each candidate while keeping the quantized features cached. It also fixes the `use_weights=false` error when class weights are set. Weighted metrics remain the default.

Tested on CPU/macOS ARM64: all 28 new regression cases fail before the fix and pass after it. All 12 existing search tests pass too.

---

Pull Request resolved: #3198
commit_hash:e02213b36f4751c0c287f5a94a4ca58e30547b77
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

using class_weights with grid_search seems to provide incorrect results

2 participants