hyperopt / hyperopt-sklearn

Hyper-parameter optimization for sklearn
hyperopt.github.io/hyperopt-sklearn
Other
1.57k stars 270 forks source link

Invalid value of `min_samples_leaf` on decision tree #166

Open jwarley opened 3 years ago

jwarley commented 3 years ago

Trying to train a decision tree

from hpsklearn import HyperoptEstimator, decision_tree
[...load data....]
estim = HyperoptEstimator(classifier=decision_tree('dt'))
estim.fit(X, y)

yields the following exception:

ERROR:hyperopt.fmin:job exception: min_samples_leaf must be at least 1 or in (0, 0.5], got 4.0

Since a float value of min_samples_leaf is interpreted as a percentage, this seems like possibly a failure to cast to int somewhere in the hpsklearn code.

jwarley commented 3 years ago

Okay, this is related to https://github.com/hyperopt/hyperopt/issues/508

I'm currently fixing this in my local copy by replacing these lines by:

    min_samples_split=scope.int(hp.uniformint(
        _name('min_samples_split'),
        2, 10)) if min_samples_split is None else min_samples_split,
    min_samples_leaf=scope.int(hp.uniformint(
        _name('min_samples_leaf'),
        1, 5)) if min_samples_leaf is None else min_samples_leaf,

I can submit a PR if that seems like an acceptable solution.