r - R 在使用 cv.tree() 时遇到致命错误
问题描述
在执行以下代码行时,我遇到了错误。
require(ISLR)
require(tree)
attach(Carseats)
hist(Sales)
high = ifelse(Sales <= 8, "No", "Yes")
Carseats = data.frame(Carseats, high)
#fit tree
tree.carseats = tree(high~. -Sales, Carseats)
summary(tree.carseats)
plot(tree.carseats)
text(tree.carseats, pretty = 0)
#for a deatailed summary of the tree, print it
tree.carseats
#creat a training and test set (250, 150) split of the 400 observations,grow the tree on the training set, and evaluate its performance on the test set
set.seed(1011)
train = sample(1:nrow(Carseats), 250)#creat training set out of n obervations of carseats
tree.carseats = tree(high~. -Sales, Carseats, subset = train)
plot(tree.carseats);text(tree.carseats, pretty = 0)
tree.pre = predict(tree.carseats, Carseats[-train,], type = "class")
with(Carseats[-train,], table(tree.pre, high))
(61 + 45) /150#erro rate of bushy tree
#using cv to prune the tree
cv.carseats = cv.tree(tree.carseats, Carseats, FUN = prune.misclass)#use misclass error as the basis for doing the pruning
cv.carseats
plot(cv.carseats)
运行以下行时,我收到“R 遇到致命错误”消息:
cv.carseats = cv.tree(tree.carseats, Carseats, FUN = prune.misclass)
解决方案
推荐阅读
- scala - 请求成功时获取“HTTP方法不允许,支持的方法:GET”
- oracle - oracle apex 开发者工具栏说明
- python - 在 python 中转换 Postman/newman 收集请求
- python - 当 Tensorflow 2.2 加载具有 NumericColumn 的 2.1 模型时,会抛出“KeyError: 'partitioner'”
- c - 即使我的条件得到验证,为什么不返回 true
- r - rasterFromXYZ 警告:数据长度不是行数的约数或倍数
- javascript - 如何在全日历中查看基于月份的数据
- angular - Ionic 3 - 带有标题的 Angular Post 不起作用
- javascript - 如何使用 jQuery 对一组元素的值求和?
- symfony - 无法使用 Loader 或 Fileloader 从捆绑包中加载 routes.yaml 配置