【问题标题】:Error in predict.NaiveBayes : "Not all variable names used in object found in newdata"-- (Although no variables are missing)predict.NaiveBayes 中的错误:“并非所有用于在 newdata 中找到的对象中的变量名称”——(尽管没有变量丢失)
【发布时间】:2021-10-06 15:46:04
【问题描述】:

我仍在通过The caret Package by Max Kuhn 学习使用caret 包,并在尝试使用plsBayesFit 模型通过predict(plsBayesFit, head(testing), type = "prob") 进行预测时陷入了16.2 Partial Least Squares Discriminant Analysis 部分,如书中所示。

使用的数据是来自mlbench包的data(Sonar),数据被拆分为:

inTrain <- createDataPartition(Sonar$Class, p = 2/3, list = FALSE)

sonarTrain <- Sonar[ inTrain, -ncol(Sonar)]
sonarTest  <- Sonar[-inTrain, -ncol(Sonar)]

trainClass <- Sonar[ inTrain, "Class"]
testClass  <- Sonar[-inTrain, "Class"]

然后进行如下预处理:

centerScale <- preProcess(sonarTrain)
centerScale

training <- predict(centerScale, sonarTrain)
testing <- predict(centerScale, sonarTest)

之后,使用plsBayesFit &lt;- plsda(training, trainClass, ncomp = 20, probMethod = "Bayes") 训练模型,然后使用predict(plsBayesFit, head(testing), type = "prob") 进行预测。

当我尝试这样做时,我收到以下错误: Error in predict.NaiveBayes(object$probModel[[ncomp[i]]], as.data.frame(tmpPred[, : Not all variable names used in object found in newdata

我检查了训练集和测试集以检查是否有任何缺失的变量,但没有。我还尝试使用 2.7.1 版本的 pls 包进行预测,该包当时用于渲染这本书,但这也给了我同样的错误。发生了什么事?

【问题讨论】:

    标签: machine-learning data-science r-caret naivebayes least-squares


    【解决方案1】:

    我尝试使用不同的模型复制您的问题,因为我也遇到过这个error,但我失败了; caret 现在的行为似乎与我使用它时不同。

    无论如何,偶然发现了这个Github-issues here,似乎klaR-package 存在特定问题。所以我的猜测是,这只是一个bug - 这里没有什么可以轻易修复的!

    【讨论】:

    • 啊,真令人失望。我会尝试看看使用以前版本的klaR 是否可以做到这一点。我没有检查backtrace() 知道是klaR 造成的。还以为是pls。无论如何,谢谢伙计。
    猜你喜欢
    • 2021-02-21
    • 1970-01-01
    • 2013-02-08
    • 1970-01-01
    • 2020-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多