【问题标题】:naive bayes classifier error in rr中的朴素贝叶斯分类器错误
【发布时间】:2013-06-23 17:07:10
【问题描述】:

我使用naiveBayes e1071 对我的数据集进行分类(分类类别:“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

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

【问题讨论】:

    标签: r machine-learning classification


    【解决方案1】:

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

    您可以尝试使用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)
    

    【讨论】:

      猜你喜欢
      • 2012-11-10
      • 2013-04-19
      • 2015-12-20
      • 2017-01-10
      • 2015-06-30
      • 2019-02-27
      • 2014-07-12
      • 2014-11-12
      相关资源
      最近更新 更多