【问题标题】:C50 code called exit with value 1 (using factor decision variable a non empty values)C50 代码调用退出值为 1(使用因子决策变量非空值)
【发布时间】:2016-09-10 05:21:03
【问题描述】:

我读到了类似的post related 来解决这个问题,但我担心这个错误代码是由其他原因引起的。我有一个包含 8 个观察值和 10 个变量的 CSV 文件:

 > str(rorIn)

'data.frame':   8 obs. of  10 variables:
 $ Acuity             : Factor w/ 3 levels "Elective  ","Emergency ",..: 1 1 2 2 1 2 2 3
 $ AgeInYears         : int  49 56 77 65 51 79 67 63
 $ IsPriority         : int  0 0 1 0 0 1 0 1
 $ AuthorizationStatus: Factor w/ 1 level "APPROVED  ": 1 1 1 1 1 1 1 1
 $ iscasemanagement   : Factor w/ 2 levels "N","Y": 1 1 2 1 1 2 2 2
 $ iseligible         : Factor w/ 1 level "Y": 1 1 1 1 1 1 1 1
 $ referralservicecode: Factor w/ 4 levels "12345","278",..: 4 1 3 1 1 2 3 1
 $ IsHighlight        : Factor w/ 1 level "N": 1 1 1 1 1 1 1 1
 $ RealLengthOfStay   : int  25 1 1 1 2 2 1 3
 $ Readmit            : Factor w/ 2 levels "0","1": 2 1 2 1 2 1 2 1

我这样调用算法:

library("C50")
rorIn <- read.csv(file = "RoRdataInputData_v1.6.csv", header = TRUE, quote = "\"")
rorIn$Readmit <- factor(rorIn$Readmit)
fit <- C5.0(Readmit~., data= rorIn)

然后我得到:

> source("~/R-workspace/src/RoR/RoR/testing.R")
c50 code called exit with value 1
> 

我正在遵循其他建议,例如: - 使用因子作为决策变量 - 避免空数据

对此有任何帮助吗?我读到这是机器学习的最佳算法之一,但我一直收到此错误。

这是原始数据集:

Acuity,AgeInYears,IsPriority,AuthorizationStatus,iscasemanagement,iseligible,referralservicecode,IsHighlight,RealLengthOfStay,Readmit
Elective  ,49,0,APPROVED  ,N,Y,SNF            ,N,25,1
Elective  ,56,0,APPROVED  ,N,Y,12345,N,1,0
Emergency ,77,1,APPROVED  ,Y,Y,OBSERVE        ,N,1,1
Emergency ,65,0,APPROVED  ,N,Y,12345,N,1,0
Elective  ,51,0,APPROVED  ,N,Y,12345,N,2,1
Emergency ,79,1,APPROVED  ,Y,Y,278,N,2,0
Emergency ,67,0,APPROVED  ,Y,Y,OBSERVE        ,N,1,1
Urgent    ,63,1,APPROVED  ,Y,Y,12345,N,3,0

提前感谢您的帮助,

大卫

【问题讨论】:

  • 你的数据是不是太小了?你有比观察更多的变量,这可能是一个问题。
  • p > n 是个问题,但即便如此,数据也相对较小。通常不建议尝试用这么少的观察结果创建一个稳健的模型。

标签: r machine-learning decision-tree


【解决方案1】:

您需要通过几种方式清理数据。

  • 只删除一层不必要的列。它们不包含任何信息并会导致问题。
  • 将目标变量rorIn$Readmit的类转换为因子。
  • 从您为训练提供的数据集中分离目标变量。

这应该可行:

rorIn <- read.csv("RoRdataInputData_v1.6.csv", header=TRUE) 
rorIn$Readmit <- as.factor(rorIn$Readmit)
library(Hmisc)
singleLevelVars <- names(rorIn)[contents(rorIn)$contents$Levels == 1]
trainvars <- setdiff(colnames(rorIn), c("Readmit", singleLevelVars))
library(C50)
RoRmodel <- C5.0(rorIn[,trainvars], rorIn$Readmit,trials = 10)
predict(RoRmodel, rorIn[,trainvars])
#[1] 1 0 1 0 0 0 1 0
#Levels: 0 1

然后,您可以通过将此预测结果与目标变量的实际值进行比较来评估准确性、召回率和其他统计数据:

rorIn$Readmit
#[1] 1 0 1 0 1 0 1 0
#Levels: 0 1

通常的方法是建立一个混淆矩阵来比较二元分类问题中的实际值和预测值。在这个小数据集的情况下,可以很容易地看到只有一个假阴性结果。因此,代码似乎运行良好,但这个令人鼓舞的结果可能由于观察次数非常少而具有欺骗性

library(gmodels)
actual <- rorIn$Readmit
predicted <- predict(RoRmodel,rorIn[,trainvars])     
CrossTable(actual,predicted, prop.chisq=FALSE,prop.r=FALSE)
# Total Observations in Table:  8  
#
# 
#              | predicted 
#       actual |         0 |         1 | Row Total | 
#--------------|-----------|-----------|-----------|
#            0 |         4 |         0 |         4 | 
#              |     0.800 |     0.000 |           | 
#              |     0.500 |     0.000 |           | 
#--------------|-----------|-----------|-----------|
#            1 |         1 |         3 |         4 | 
#              |     0.200 |     1.000 |           | 
#              |     0.125 |     0.375 |           | 
#--------------|-----------|-----------|-----------|
# Column Total |         5 |         3 |         8 | 
#              |     0.625 |     0.375 |           | 
#--------------|-----------|-----------|-----------|

在更大的数据集上,如果没有必要,将数据集分为训练数据和测试数据会很有用。有很多关于机器学习的优秀文献可以帮助您微调模型及其预测。

【讨论】:

  • RHertel,感谢您的详细回复。它在修复 1 级问题后起作用。我更喜欢通过以下方式调用算法:fit &lt;- C5.0 (y ~ x1 + x2 + x3, data =train, trials=10)。对于长公式,我以前使用as.formula(paste("a +", "b")) 保存它。但这只是偏好问题,我得到相同的结果。非常感谢!
  • @DavidLeal 不客气!我很高兴听到它现在有效 - 知道你有大量的观察结果令人欣慰。关于不同的语法,我想这属于“不止一种给猫剥皮的方法”的类别;-) 我不知道 C5.0 的 formula 语法,但它肯定是有道理的。如果答案有助于解决您的问题,请通过单击左侧的勾号来考虑accepting it。干杯,
猜你喜欢
  • 2019-01-25
  • 2014-05-13
  • 2016-11-27
  • 1970-01-01
  • 1970-01-01
  • 2021-07-23
  • 2021-07-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多