r中的朴素贝叶斯分类器错误(naive bayes classifier error in r)

编程入门 行业动态 更新时间:2024-10-20 20:59:36
r中的朴素贝叶斯分类器错误(naive bayes classifier error in r)

我使用naiveBayes e1071对我的数据集进行分类(Classification class:“V32”0/1)。

这是我做的:

d <- read.table("Modeling_Data.txt",header=FALSE,sep="\t", comment.char="",quote="") #divide into training and test data 70:30 trainingIndex <- createDataPartition(d$V32, p=.7, list=F) d.training <- d[trainingIndex,] d.testing <- d[-trainingIndex,] nb.classifier <- naiveBayes(as.factor(d$V32) ~ ., data = d.training)

但我得到这个错误:

Error in names(dimnames(tables[[i]])) <- c(Yname, colnames(x)[i]) : attempt to set an attribute on NULL predict(nb.classifier,d.testing[,-50000]) Error in predict(nb.classifier, d.testing[, -50000]) : object 'nb.classifier' not found

我试图使用包含数据集(虹膜),一切正常。 我的方法有什么问题?

I use naiveBayes e1071 for classifying my data set (Classification class: "V32" 0/1).

Here is what I do:

d <- read.table("Modeling_Data.txt",header=FALSE,sep="\t", comment.char="",quote="") #divide into training and test data 70:30 trainingIndex <- createDataPartition(d$V32, p=.7, list=F) d.training <- d[trainingIndex,] d.testing <- d[-trainingIndex,] nb.classifier <- naiveBayes(as.factor(d$V32) ~ ., data = d.training)

But I get this error:

Error in names(dimnames(tables[[i]])) <- c(Yname, colnames(x)[i]) : attempt to set an attribute on NULL predict(nb.classifier,d.testing[,-50000]) Error in predict(nb.classifier, d.testing[, -50000]) : object 'nb.classifier' not found

I tried to use the included the data set (iris) and everything works fine. What's wrong with my approach?

最满意答案

似乎构建模型失败(因此未构造分类器)。 如果不查看您的数据,我最好的猜测是您的案例不完整。

您可以尝试使用complete.cases删除缺少数据的案例,如下所示。

d <- read.table("Modeling_Data.txt",header=FALSE,sep="\t",comment.char="",quote="") # remove incomplete cases d[complete.cases(d),] # divide into training and test data 70:30 trainingIndex <- createDataPartition(d$V32, p=.7, list=F)

Seems like building of the model failing (and as a result the classifier is not constructed). Without looking at your data, my best guess would be that you have incomplete cases.

You could try removing cases with missing data using complete.cases as follows.

d <- read.table("Modeling_Data.txt",header=FALSE,sep="\t",comment.char="",quote="") # remove incomplete cases d[complete.cases(d),] # divide into training and test data 70:30 trainingIndex <- createDataPartition(d$V32, p=.7, list=F)

更多推荐

本文发布于:2023-08-04 07:43:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1413102.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:朴素   错误   贝叶斯   naive   classifier

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!