错误box.col:fancyRpartPlot()上的非法值和R中的rpart.plot()

时间:2017-04-12 19:19:26

标签: r rpart

我正在练习“泰坦尼克号:灾难中的机器学习”教程。来自kaggle 有人可以帮我解决这个错误吗?它与函数rpart.plot(fit)和fancyRpartPlot(fit)和example(rpart.plot)相同,而plot(fit)工作正常。

fancyRpartPlot(fit) Error: box.col: illegal value
fit is : fit <- rpart(Survived ~ Sex, data=train, method="class")

我尝试了以下内容: 遵循github页面(https://github.com/trevorstephens/titanic/blob/master/Tutorial3.R)中的实现中的确切步骤。

卸载并安装了整个R和添加的软件包。

我尝试调试fancyRpartPlot()并在函数中调用

box.col = pals[col.index],
pals : chr[1:30] "#F7FCF5" "E5F5E0" "#C7E9C0" .......so on
col.index : num[1:3] 4 5 9

box.col将根据索引显示这些值:“#A1D99B”“#74C476”“#9ECAE1”

我试过很多清除这个问题,可能是一个小问题。我错过了什么?

print(fit):

n= 891
node), split, n, loss, yval, (yprob)
  * denotes terminal node
1) root 891 342 0 (0.6161616 0.3838384)
2) Sex=male 577 109 0 (0.8110919 0.1889081) *
3) Sex=female 314  81 1 (0.2579618 0.7420382) *

traceback():

6: stop(..., call. = FALSE) 
5: stop0(deparse(substitute(object)), ": illegal value")
4: is.specified(box.col)
3: handle.box.palette.args(obj, trace, box.col, box.palette, pal.thresh, 
   pal.node.fun, node.fun.name, class.stats, node.labs)
2: rpart.plot::prp(model, type = 2, extra = extra, box.col = pals[col.index], 
   nn = TRUE, varlen = 0, faclen = 0, shadow.col = "grey", fallen.leaves = TRUE, 
   branch.lty = 3, ...)
1: fancyRpartPlot(fit)

sessionInfo():

R version 3.0.2 (2013-09-25)
Platform: x86_64-pc-linux-gnu (64-bit)
locale:
[1] LC_CTYPE=en_IN.UTF-8         LC_NUMERIC=C   LC_TIME=en_IN.UTF-8
[4] LC_COLLATE=en_IN.UTF-8     LC_MONETARY=en_IN.UTF-8    LC_MESSAGES=en_IN.UTF-8 
[7] LC_PAPER=en_IN.UTF-8       LC_NAME=C                  LC_ADDRESS=C
[10] LC_TELEPHONE=C             LC_MEASUREMENT=en_IN.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base
other attached packages:
[1] RColorBrewer_1.1-2 rpart.plot_2.1.1   rattle_4.1.0       rpart_4.1-10
loaded via a namespace (and not attached):
[1] magrittr_1.5  RGtk2_2.20.31 stringi_1.1.5 tools_3.0.2 

例(rpart.plot):

rprt.p> old.par <- par(mfrow=c(2,2))                    # put 4 figures on one page
rprt.p> data(ptitanic)
rprt.p> #---------------------------------------------------------------------------
rprt.p>
rprt.p> binary.model <- rpart(survived ~ ., data=ptitanic, cp=.02)
rprt.p>                                         # cp=.02 for small demo tree
rprt.p>
rprt.p> rpart.plot(binary.model,
rprt.p+            main="titanic survived\n(binary response)")
Error: box.col: illegal value

0 个答案:

没有答案