mlr-org / mlr3learners

Recommended learners for mlr3
https://mlr3learners.mlr-org.com
GNU Lesser General Public License v3.0
91 stars 15 forks source link

Error in setting monotone_constraints for Xgboost learner #201

Closed nlistat closed 3 years ago

nlistat commented 3 years ago

Hello,

Firstly thanks a lot for creating and maintaining the mlr3 package, which is fantastic and easy to use. Here I would like to report some errors regarding the Xgboost learner.

When setting monotone_constraints for classif.xgboost learner, there are errors which do not allow multiple numerics or a string containing multiple numbers, in other words only a single integer value is allowed as monotonic constraints.

For instance, when trying following code,

xg.lrn = mlr3::lrn('classif.xgboost', id = 'Xgboost', monotone_constraints = c(0,1))

xg.lrn = mlr3::lrn('classif.xgboost', id = 'Xgboost', monotone_constraints = rep(1,30))

there is an error:

Error in self$assert(xs) : Assertion on 'xs' failed: monotone_constraints: Must have length 1.

When trying the code which uses a string,

xg.lrn = mlr3::lrn('classif.xgboost', id = 'Xgboost', monotone_constraints = paste('(', rep(1,30), ')', sep = ''))

there is an error:

Error in self$assert(xs) : Assertion on 'xs' failed: monotone_constraints: Must be of type 'single integerish value', not 'character'.

The code which does not cause error is:

xg.lrn = mlr3::lrn('classif.xgboost', id = 'Xgboost', monotone_constraints = 1)

This setting would not fit for the situation that different constraints should be applied to different columns of the data. Can you please fix it? Thank you!

Below is my session info:

R version 4.0.4 (2021-02-15) Platform: x86_64-apple-darwin17.0 (64-bit) Running under: macOS Big Sur 10.16

Matrix products: default LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

Random number generation: RNG: Mersenne-Twister Normal: Inversion Sample: Rounding

locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages: character(0)

other attached packages: [1] mlr3_0.11.0

mllg commented 3 years ago

Should be fixed now via #194.