1
votes

I'm creating rules from the decision tree generated by mlr package wrapper learner classif.rpart, how to print the rules as in rpart.rules and how to visualize as in rpart.plot

Created the learner using classif.rpart, trained and fitted the model, tried to plot using rpart.plot and saying error as Not an rpart object

dt_mod <- mlr::train(fused_dt, classif.task)
dt_mod
library(rpart.plot)
rpart.plot(dt_mod$learner.model, roundint=FALSE, varlen=3, type = 3, clip.right.labs = FALSE, yesno = 2)
rpart.rules(dt_mod$learner.model, roundint = FALSE)

I except the rules to be listed and tree to be visualized

1
The learner is made with makeFilterWrapper, with fw.method, then parameter tuning is done, will that model considered as rpart object?hanzgs

1 Answers

3
votes

You can access the model a learner has induced directly using getLearnerModel():

iris.model = train(makeLearner("classif.rpart"), iris.task)
rpart.plot(getLearnerModel(iris.model))

If your learner is wrapped, pass the more.unwrap = TRUE option:

rpart.plot(getLearnerModel(iris.model, more.unwrap = TRUE))