r - 错误 : *** line 1 of `undefined.cases' : bad value of . .. 属性

标签 r machine-learning c5.0

我正在训练决策树 C5.0,一切都运行良好,直到我尝试预测测试数据集中的值。我不确定错误的含义:

library(pacman)
p_load(tidyverse, NHANES, C50)

rows <- sample(nrow(NHANES), as.integer(0.75 * nrow(NHANES)))

nhanes_train <- NHANES[rows,] %>%
  select(SleepTrouble, everything(), -ID)
nhanes_test <- NHANES[-rows,] %>%
  select(SleepTrouble, everything(), -ID)

nhanes_tree <- C5.0(nhanes_train[-1], nhanes_train$SleepTrouble)

nhanes_tree_pred <- predict(nhanes_tree, nhanes_test)

输出:

Error: *** line 1 of undefined.cases': bad value of c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,' for attribute `SurveyYr' Error limit exceeded

最佳答案

似乎当你有非数字数据如因子时,你必须使用函数的公式版本。这很好用:

nhanes_tree <- C5.0(SleepTrouble ~ ., nhanes_train)
nhanes_tree_pred <- predict(nhanes_tree, nhanes_test)

来自文档:

When using the formula method, factors and other classes are preserved (i.e. dummy variables are not automatically created). This particular model handles non-numeric data of some types (such as character, factor and ordered data).

关于r - 错误 : *** line 1 of `undefined.cases' : bad value of . .. 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60445014/

相关文章:

r - 如何在 R 中使用 SVM 进行递归特征消除

matplotlib - 如何使用 matplotlib 绘制非线性模型?

r - 如何从 R 中的防风草模型中提取分类树?

r - 如何在 R 中创建按变量分组的新数据表

r - 将 Markdown 转换为 Rd,还是定义自定义 Markdown 转换规则?

r - R中与调查设计相关的问题

javascript - 如何从 Highcharter 股票图表中提取最小和最大日期?

machine-learning - 如何解释不平衡数据中的高 AUC-ROC 和平庸的精确度和召回率?