FFTrees
FFTrees copied to clipboard
Add support (either functionality and/or documentation) on integrating with tidymodels
Hello,
I am playing a bit with your package and tried to incorporate your FFTrees function into mlr. Here is the piece of code I came up with.
# step 1 - set up properties of the learner
makeRLearner.classif.fftree = function() {
makeRLearnerClassif(
cl = "classif.fftree",
package = "FFTrees",
par.set = makeParamSet(
makeNumericLearnerParam(id = "max.levels", default = 4, lower = 1),
makeNumericLearnerParam(id = "sens.w", default = .5, lower = 0, upper = 1),
makeDiscreteLearnerParam(id = "stopping.rule", default = "exemplars", values = c("exemplars", "levels", "statdelta")),
makeNumericLearnerParam(id = "stopping.par", default = .1, lower = 0),
makeDiscreteLearnerParam(id = "goal", default = "wacc", values = c("acc", "wacc", "bacc")),
makeDiscreteLearnerParam(id = "goal.chase", default = "bacc", values = c("acc", "wacc", "bacc", "cost")),
makeDiscreteLearnerParam(id = "goal.threshold", default = "bacc", values = c("acc", "wacc", "bacc")),
makeDiscreteLearnerParam(id = "numthresh.method", default = "o", values = c("o", "m")),
makeLogicalLearnerParam(id = "repeat.cues", default = TRUE),
makeLogicalLearnerParam(id = "do.comp", default = FALSE, tunable = FALSE)
),
properties = c("twoclass", "numerics", "factors", "prob"),
name = "Fast and Frugal decision tree",
short.name = "fftree"
)
}
# step 2 - create the train function
trainLearner.classif.fftree = function(.learner, .task, .subset, .weights = NULL, ...) {
f = getTaskFormula(.task)
d = getTaskData(.task, .subset)
FFTrees::FFTrees(f, data = d, ...)
}
# step 3 - create the predict function
predictLearner.classif.fftree = function(.learner, .model, .newdata, ...) {
type = switch(.learner$predict.type, prob = "prob", "class")
p = predict(.model$learner.model, newdata = .newdata, type = type, ...)
return(p)
}
# step 4 - register the functions
registerS3method("makeRLearner", "classif.fftree", makeRLearner.classif.fftree)
registerS3method("trainLearner", "classif.fftree", trainLearner.classif.fftree)
registerS3method("predictLearner", "classif.fftree", predictLearner.classif.fftree)
I hope this will help.
Cheers, Mathieu
This is awesome, thanks so much @MathieuMarauri !!!! I tried doing something similar a while ago with mixed success. Your solution looks very clean. Thanks!!
Caret is maintained but will not develop much further. making this work with parsnip would be really cool though!
Changing title to integration with tidymodels as that seems to be the most active ecosystem for ML in R these days