R 无效';类型';(性质)论据
这是关于该主题的错误消息。当我尝试运行naive.bayes分类器时,我遇到了这个错误。以下是我的列车数据摘要:R 无效';类型';(性质)论据,r,classification,text-classification,naivebayes,document-classification,R,Classification,Text Classification,Naivebayes,Document Classification,这是关于该主题的错误消息。当我尝试运行naive.bayes分类器时,我遇到了这个错误。以下是我的列车数据摘要: 'data.frame': 7269 obs. of 193 variables: $ pid : int 2 4 5 7 10 11 14 18 25 31 ... $ acquir : int 0 0 0 0 1 1 0 0 0 0 ... $ addit : int 0 0 0 0 2 2 0 0 0 0 ... $ agre
'data.frame': 7269 obs. of 193 variables:
$ pid : int 2 4 5 7 10 11 14 18 25 31 ...
$ acquir : int 0 0 0 0 1 1 0 0 0 0 ...
$ addit : int 0 0 0 0 2 2 0 0 0 0 ...
$ agre : int 0 0 0 0 0 0 0 0 0 0 ...
$ agreement : int 0 0 0 0 0 0 0 0 0 0 ...
$ also : int 1 0 0 0 2 2 0 0 0 0 ...
$ american : int 0 0 0 0 0 0 0 0 0 0 ...
$ announc : int 0 0 0 0 0 0 0 0 0 0 ...
$ annual : int 0 0 0 0 0 0 0 0 2 0 ...
$ approv : int 0 3 0 0 0 0 0 0 0 0 ...
$ april : int 0 0 0 0 0 0 0 0 1 0 ...
$ bank : int 0 7 0 0 0 0 0 0 0 0 ...
$ base : int 0 0 0 0 0 0 0 0 0 0 ...
.
.
$... all of them are integer, except the class column
.
.
$ class : Factor w/ 10 levels "acq","corn","crude",..: 1 1 4 4 9 1 4 3 1 4 ...
这是naive.bayes()
行:
model <- naiveBayes(as.factor(class) ~ ., data = as.matrix(train), laplace = 3)
最终,由于
as.matrix(train)
,您的数据被转换为字符。试一试
model <- naiveBayes(class ~ ., data=train, laplace = 3)
model由于as.matrix(train)
,最终您的数据被转换为字符。试试model@jogo它成功了!谢谢我想接受你的回答,但是怎么接受呢?我现在已经回答了。第一种变体也有效还是只有第二种?我刚试过第一种。它成功了。没有试过其他人。
model <- naiveBayes(class ~ ., data=train, laplace = 3)
model <- naiveBayes(train$class ~ ., data=train[, -c("class")], laplace = 3)