Skip to content

fix: keep bool parameters as bool in sklearn_tuner (#108) - #122

Open
Nas01010101 wants to merge 1 commit into
huawei-noah:masterfrom
Nas01010101:fix/sklearn-tuner-bool-108
Open

fix: keep bool parameters as bool in sklearn_tuner (#108)#122
Nas01010101 wants to merge 1 commit into
huawei-noah:masterfrom
Nas01010101:fix/sklearn-tuner-bool-108

Conversation

@Nas01010101

Copy link
Copy Markdown

Summary

sklearn_tuner int-casts every discrete numeric hyper-parameter:

if space.paras[k].is_numeric and space.paras[k].is_discrete:
    hyp[k] = int(hyp[k])

BoolPara reports both is_numeric and is_discrete as True, so a boolean hyper-parameter (e.g. a RandomForest's bootstrap) is cast to 0/1. Modern scikit-learn then rejects it:

The 'bootstrap' parameter ... must be an instance of 'bool' ... Got 0 instead.

This is issue #108.

Fix

Special-case BoolPara so boolean parameters stay python bool, and only int-cast the remaining (non-bool) discrete numerics.

Tests

Adds test/test_sklearn_tuner_bool.py — a recorder estimator that asserts the parameter type it receives at fit. Fails before the fix (bool coerced to int), passes after.

1 passed

Closes #108.

@CLAassistant

CLAassistant commented May 29, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

`sklearn_tuner` casts every numeric discrete hyper-parameter to `int`
before passing it to the estimator. `BoolPara` reports both
`is_numeric` and `is_discrete` as True, so a `bool` parameter (e.g.
`bootstrap`/`warm_start` of RandomForest) reaches the estimator as
`0`/`1` instead of `False`/`True`. Recent scikit-learn validates the
parameter type and raises, e.g. "The 'bootstrap' parameter ... must be
an instance of 'bool' ... Got 0 instead."

Keep bool parameters as python `bool`; only int-cast the remaining
non-bool discrete numeric parameters. Adds a regression test that
records the parameter types received by the estimator.
@Nas01010101
Nas01010101 force-pushed the fix/sklearn-tuner-bool-108 branch from 660a47a to 582599c Compare May 29, 2026 12:02
@Nas01010101

Copy link
Copy Markdown
Author

Verified this still applies cleanly against current master (0 commits behind) and the added test still fails on revert.

Heads up for merge order: this PR and #123 both touch the for k in hyp: loop body in sklearn_tuner.py (this one changes the cast logic, #123 wraps the loop in warnings.catch_warnings()), so merging both will produce a conflict on whichever lands second. Happy to rebase the other one once you've merged one of them — just ping the branch.

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

Successfully merging this pull request may close these issues.

sklearn_tuner change Bool to Int

2 participants