teazrq / RLT

:deciduous_tree: Reinforcement Learning Trees
https://teazrq.github.io/RLT/
11 stars 5 forks source link

Extracting the Tree Rules from RLT #6

Open swaheera opened 2 years ago

swaheera commented 2 years ago

Hello!

I am using the RLT library in R for the following example (classification):

library(RLT)
data(iris)
fit = RLT(iris[,c(1,2,3,4)], iris$Species, model = "classification", ntrees = 1)

From here, is it possible to extract the "rules" from this decision tree?

For example, if you use the CART Decision Tree model:


library(rpart)
library(rpart.plot)

fit <-rpart( Species ~. , data = iris)
rpart.plot(fit)

 rpart.rules(fit)
    Species  seto vers virg                                               
     setosa [1.00  .00  .00] when Petal.Length <  2.5                     
 versicolor [ .00  .91  .09] when Petal.Length >= 2.5 & Petal.Width <  1.8
  virginica [ .00  .02  .98] when Petal.Length >= 2.5 & Petal.Width >= 1.8

Is it possible to do this with the RLT library?

Thanks!

teazrq commented 2 years ago

Sorry for the late reply. But yes, we implemented a new function get.one.tree() that is able to perform this task. You can find an example in the test_reg.r file. Let me know if does work as intended or if there are any bugs. This new version is still being developed.