小编Ash*_*mes的帖子

"rpart"对象错误的预测无效

我正在使用这个CRAN文档(https://cran.r-project.org/web/packages/FSelector/FSelector.pdf)第4页的最佳首次搜索的确切代码,该文档使用了iris数据集.它在虹膜数据集上运行得很好,但不适用于我的ndata.我的数据有37个预测变量(数字和分类),第38列是类预测.

我收到错误:

Error in predict.rpart(tree, test, type = "c") : 
   Invalid prediction for "rpart" object
Run Code Online (Sandbox Code Playgroud)

我认为这个来自这一行:

     error.rate = sum(test$Class != predict(tree, test, type="c")) / nrow(test)
Run Code Online (Sandbox Code Playgroud)

我已经尝试过调试和回溯,但我不明白为什么会发生这种错误(就像我说的那样,它不能用虹膜数据重现).

这是我的一些数据,因此您可以看到我正在使用的内容:

> head(data)
Numeric Binary Binary.1 Categorical Binary.2 Numeric.1 Numeric.2 Numeric.3     Numeric.4 Numeric.5 Numeric.6
1      42      1        0           1        0  27.38953  38.93202  27.09122  38.15687  9.798653  18.57313
2      43      1        0           3        0  76.34071  75.18190  73.66722  72.39449 23.546124  54.29957
3      67      0        0           1        0 485.87158 287.35052 471.58863 281.55261 73.454080 389.40092
4      49 …
Run Code Online (Sandbox Code Playgroud)

r prediction rpart fselector

0
推荐指数
1
解决办法
9896
查看次数

标签 统计

fselector ×1

prediction ×1

r ×1

rpart ×1