Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 决策树中的前n类叶节点_R_Decision Tree_Rpart - Fatal编程技术网

R 决策树中的前n类叶节点

R 决策树中的前n类叶节点,r,decision-tree,rpart,R,Decision Tree,Rpart,我正在使用rpartpacake ofR,我想为叶节点提取前2个预测类,而不仅仅是最佳类。 以iris数据为例: fit <- rpart(Species ~ Sepal.Length + Sepal.Width + Petal.Length + Petal.Width, data = iris) print(fit) fit=2.45 100 50 versicolor(0.00000000 0.50000000 0.50000000) 6) 花瓣宽度=1.75 46 1维吉尼亚(0.

我正在使用
rpart
pacake of
R
,我想为叶节点提取前2个预测类,而不仅仅是最佳类。 以
iris
数据为例:

fit <- rpart(Species ~ Sepal.Length + Sepal.Width + Petal.Length + Petal.Width, data = iris)
print(fit)
fit=2.45 100 50 versicolor(0.00000000 0.50000000 0.50000000)
6) 花瓣宽度<1.75 54 5花色(0.00000000 0.90740741 0.09259259)*
7) 花瓣宽度>=1.75 46 1维吉尼亚(0.00000000 0.02173913 0.97826087)*
我想知道每个叶节点(比如节点7)的第二个最佳预测物种是什么。默认情况下,它只打印出最佳预测物种
virginica

更一般地说,我想知道前n个预测类


是否可以在不更改
rpart
的源代码的情况下从
fit
提取此信息?

您可以通过

> fit$frame$yval2
                                             nodeprob
[1,] 1 50 50 50 0.3333333 0.33333333 0.33333333 1.0000000
[2,] 1 50  0  0 1.0000000 0.00000000 0.00000000 0.3333333
[3,] 2  0 50 50 0.0000000 0.50000000 0.50000000 0.6666667
[4,] 2  0 49  5 0.0000000 0.90740741 0.09259259 0.3600000
[5,] 3  0  1 45 0.0000000 0.02173913 0.97826087 0.3066667
或者你可以从电视上看到

fancyRpartPlot(fit)
从拨浪鼓包装-它是彩色的


我想你可能会想把它用于更复杂的事情,但是如果树很简单,那么图形就可以了。

它有帮助吗?
fancyRpartPlot(fit)