crflynn / skranger

scikit-learn compatible Python bindings for ranger C++ random forest library
https://skranger.readthedocs.io/en/stable/
GNU General Public License v3.0
52 stars 7 forks source link

Enabling `what` parameter from ranger.predict to enable predictions via quantile random forest #157

Open jmaddalena opened 8 months ago

jmaddalena commented 8 months ago

In the ranger library, the following is presented as the arguments for the predict call from the ranger model:

## S3 method for class 'ranger'
predict(
object,
data = NULL,
predict.all = FALSE,
num.trees = object$num.trees,
type = "response",
se.method = "infjack",
quantiles = c(0.1, 0.5, 0.9),
what = NULL,
seed = NULL,
num.threads = NULL,
verbose = TRUE,
...
)

The argument what is specified as:

User specified function for quantile prediction used instead of quantile. Must return numeric vector, see examples.

This can be used to generate estimates of uncertainty via quantile random forest via simulation, as noted in this example in the ranger documentation:

## Quantile regression forest with user-specified function
rf <- ranger(mpg ~ ., mtcars[1:26, ], quantreg = TRUE)
pred <- predict(rf, mtcars[27:32, ], type = "quantiles",
what = function(x) sample(x, 10, replace = TRUE))
pred$predictions

Is there a way to do this in skranger by other means or is this a feature you would consider supporting in the future?