如果您运行以下命令:
library(RWeka)
data(iris)
res = J48(Species ~., data = iris)
res
将是J48
继承自的类列表Weka_tree
。如果你打印它
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
我想按从右到左的顺序获取属性及其值。所以对于这种情况:
Petal.Width, Petal.Width, Petal.Length, Petal.Length.
我尝试将 res 输入到一个因子并运行命令:
str_extract(paste0(x, collapse=""), perl("(?<=\\|)[A-Za-z]+(?=\\|)"))
没有成功。只是要记住,我们应该忽略左边的字符。