如果您运行以下命令:
library(RWeka)
data(iris)
res = J48(Species ~., data = iris)
你会得到以下树:
R> res
J48 pruned tree
------------------
Petal.Width <= 0.6: setosa (50.0)
Petal.Width > 0.6
| Petal.Width <= 1.7
| | Petal.Length <= 4.9: versicolor (48.0/1.0)
| | Petal.Length > 4.9
| | | Petal.Width <= 1.5: virginica (3.0)
| | | Petal.Width > 1.5: versicolor (3.0/1.0)
| Petal.Width > 1.7: virginica (46.0/1.0)
Number of Leaves : 5
Size of the tree : 9
现在将其复制并粘贴到文本文件中并保存 - 这是我的输入文件。我想以一种格式获取每个节点(父亲)及其子节点(这只是一个示例)的列表,就像我在 R 中运行这棵树并使用 as.party 一样。(记住我不能使用它,因为它只是一个txt格式)。我想以与在 partykit 包中使用 x$kids 相同的方式获取节点及其孩子的列表。我该怎么做?