无法在R中使用插入符号提取预测



我完全被随机森林分类模型卡住了,因为我无法提取预测。我真的没有线索了,因为:

predict(forest.model1, titanic.final.test)

工作起来很有魅力,而

extractPrediction(list(forest.model1), testX=titanic.final.test[,-2], testY=titanic.final.test[,2])

这应该是等价的,给了我这个错误:

Error in predict.randomForest(modelFit, newdata) : 
  variables in the training data missing in newdata

这是我的列车控制:

forest.fitControl <- trainControl( method = "repeatedcv", repeats = 5, 
summaryFunction = twoClassSummary, classProbs=TRUE,
returnData=TRUE, seeds=NULL, savePredictions=TRUE, returnResamp="all")

知道吗?

Test和Train需要具有相同的结构(即所有相同的列)。因此,我唯一的猜测是,否定第二列会导致与用于训练模型的数据不同的结构。如果看不到训练与测试数据的结构,很难知道。框架。

查看代码后编辑:从您的回购中重新创建了此。。。当然,它不应该是您为testX提取并用于testY的第一列。类似于:

extractPrediction(list(forest.model1), testX=titanic.final.test[,-1], testY=titanic.final.test[,1])

最新更新