插入:尝试预测但预测行不同

时间:2015-08-15 19:34:32

标签: r machine-learning r-caret

我已经创建并调整了多个模型,但是当我尝试预测它们时,我遇到了问题。我首先运行我的代码来调整LDA模型。

library(MASS)
library(caret)
library(randomForest)
data(survey)
data<-survey

#create training and test set
split <- createDataPartition(data$W.Hnd, p=.8)[[1]]
train<-data[split,]
test<-data[-split,]


#creating training parameters
control <- trainControl(method = "cv",
                        number = 10, 
                        p =.8, 
                        savePredictions = TRUE, 
                        classProbs = TRUE, 
                        summaryFunction = twoClassSummary)

#fitting and tuning model
lda_tune <- train(W.Hnd ~ . , 
            data=train, 
            method = "glm" ,
            metric = "ROC",
            trControl = control)

然而,当我跑 results <- predict(rf_tune, newdata=test)

当测试集有46行时,输出只有32行。这是有问题的,因为我用多个模型的预测值创建data.frame测试结果,以使用混淆矩阵进行分析。例如,当我运行这个

results<-data.frame(obs = test$W.Hnd, lda = predict(lda_tune, newdata = test))

我收到错误Error in $&lt; - .data.frame ( tmp , "rf_results", value = c(2L, 2L, 2L, : replacement has 32 rows, data has 46

有人可以向我解释为什么当有明确的46个预测值或者我明确地调用模型来预测测试集中的值时,插入符号返回32个预测值?

0 个答案:

没有答案