在预测NaiveBayes模型时出现错误:”Not all variable names used in object found in newdata”– (尽管没有变量缺失)

我还在学习使用caret包,通过Max Kuhn的caret包,在尝试使用plsBayesFit模型进行预测时,卡在了16.2部分最小二乘判别分析部分,如书中所示,使用predict(plsBayesFit, head(testing), type = "prob")进行预测。

所使用的数据是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)centerScaletraining <- predict(centerScale, sonarTrain)testing <- predict(centerScale, sonarTest)

之后,使用plsBayesFit <- 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

我已经检查了训练集和测试集,确认没有变量缺失。我还尝试使用用于渲染该书时的pls包的2.7.1版本进行预测,但同样出现了相同的错误。发生了什么?


回答:

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

无论如何,我偶然发现了这个Github问题这里,看起来klaR包存在一个特定的问题。所以我的猜测是,这仅仅是一个bug – 这里无法立即修复!

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注