我收到以下错误
名为exit的c50代码,值为1
我是在Kaggle提供的泰坦尼克号数据上这么做的
# Importing datasets
train <- read.csv("train.csv", sep=",")
# this is the structure
str(train)产出:-
'data.frame': 891 obs. of 12 variables:
$ PassengerId: int 1 2 3 4 5 6 7 8 9 10 ...
$ Survived : int 0 1 1 1 0 0 0 0 1 1 ...
$ Pclass : int 3 1 3 1 3 3 1 3 3 2 ...
$ Name : Factor w/ 891 levels "Abbing, Mr. Anthony",..: 109 191 358 277 16 559 520 629 417 581 ...
$ Sex : Factor w/ 2 levels "female","male": 2 1 1 1 2 2 2 2 1 1 ...
$ Age : num 22 38 26 35 35 NA 54 2 27 14 ...
$ SibSp : int 1 1 0 1 0 0 0 3 0 1 ...
$ Parch : int 0 0 0 0 0 0 0 1 2 0 ...
$ Ticket : Factor w/ 681 levels "110152","110413",..: 524 597 670 50 473 276 86 396 345 133 ...
$ Fare : num 7.25 71.28 7.92 53.1 8.05 ...
$ Cabin : Factor w/ 148 levels "","A10","A14",..: 1 83 1 57 1 1 131 1 1 1 ...
$ Embarked : Factor w/ 4 levels "","C","Q","S": 4 2 4 4 4 3 4 4 4 2 ...然后我尝试使用c5.0dtree
# Trying with C5.0 decision tree
library(C50)
#C5.0 models require a factor outcome otherwise error
train$Survived <- factor(train$Survived)
new_model <- C5.0(train[-2],train$Survived)因此,运行上面的行会给出以下错误
c50 code called exit with value 1我不知道到底出了什么问题?我在不同的数据集上使用了类似的代码,它运行得很好。对如何调试我的代码有什么想法吗?
-Thanks
发布于 2014-04-02 07:34:37
对于任何感兴趣的人,可以在这里找到数据:http://www.kaggle.com/c/titanic-gettingStarted/data。我想你需要注册才能下载。
关于你的问题,首先我认为你想写
new_model <- C5.0(train[,-2],train$Survived)接下来,注意Cabin和Embarked列的结构。这两个因素都有一个空字符作为级别名(使用levels(train$Embarked)检查)。这就是C50倒下的地方。如果你修改你的数据
levels(train$Cabin)[1] = "missing"
levels(train$Embarked)[1] = "missing"您的算法现在将无错误地运行。
发布于 2015-08-31 22:21:39
以防万一。您可以通过以下方法查看错误
summary(new_model)此外,当变量的名称中有一个特殊字符时,也会发生此错误。例如,如果在变量名中有“я”(来自俄罗斯字母)字符,则会出现此错误。
发布于 2014-04-08 08:11:26
以下是最后成功的原因:-
在阅读了这个帖子之后,得到了这个想法
library(C50)
test$Survived <- NA
combinedData <- rbind(train,test)
combinedData$Survived <- factor(combinedData$Survived)
# fixing empty character level names
levels(combinedData$Cabin)[1] = "missing"
levels(combinedData$Embarked)[1] = "missing"
new_train <- combinedData[1:891,]
new_test <- combinedData[892:1309,]
new_model <- C5.0(new_train[,-2],new_train$Survived)
new_model_predict <- predict(new_model,new_test)
submitC50 <- data.frame(PassengerId=new_test$PassengerId, Survived=new_model_predict)
write.csv(submitC50, file="c50dtree.csv", row.names=FALSE)这背后的直觉是这样的训练和测试数据集将有一致的因素水平。
https://stackoverflow.com/questions/22803310
复制相似问题