Whats the difference between
predict(rf, newdata=testSet)
and
predict(rf$finalModel, newdata=testSet)
i train the model with preProcess=c("center", "scale")
tc <- trainControl("repeatedcv", number=10, repeats=10, classProbs=TRUE, savePred=T)
rf <- train(y~., data=trainingSet, method="rf", trControl=tc, preProc=c("center", "scale"))
and i receive 0 true positives when i run it on a centered and scaled testSet
testSetCS <- testSet
xTrans <- preProcess(testSetCS)
testSetCS<- predict(xTrans, testSet)
testSet$Prediction <- predict(rf, newdata=testSet)
testSetCS$Prediction <- predict(rf, newdata=testSetCS)
but receive some true positives when i run it on an unscaled testSet. I have to use the rf$finalModel to receive some true postives on the centered and scaled testSet and the rf object on the unscaled...what am i missing?
edit
tests:
tc <- trainControl("repeatedcv", number=10, repeats=10, classProbs=TRUE, savePred=T)
RF <- train(Y~., data= trainingSet, method="rf", trControl=tc) #normal trainingData
RF.CS <- train(Y~., data= trainingSet, method="rf", trControl=tc, preProc=c("center", "scale")) #scaled and centered trainingData
on normal testSet:
RF predicts reasonable (Sensitivity= 0.33, Specificity=0.97)
RF$finalModel predicts bad (Sensitivity= 0.74, Specificity=0.36)
RF.CS predicts reasonable (Sensitivity= 0.31, Specificity=0.97)
RF.CS$finalModel same results like RF.CS (Sensitivity= 0.31, Specificity=0.97)
on centered and scaled testSetCS:
RF predicts very bad (Sensitivity= 0.00, Specificity=1.00)
RF$finalModel predicts reasonable (Sensitivity= 0.33, Specificity=0.98)
RF.CS predicts like RF (Sensitivity= 0.00, Specificity=1.00)
RF.CS$finalModel predicts like RF (Sensitivity= 0.00, Specificity=1.00)
so it seems as if the $finalModel needs the same format of trainingSet and testSet whereas the trained object accepts only uncentered and unscaled data, regardless of the selected preProcess parameter?
prediction code (where testSet is normal data and testSetCS is centered and scaled ):
testSet$Prediction <- predict(RF, newdata=testSet)
testSet$PredictionFM <- predict(RF$finalModel, newdata=testSet)
testSet$PredictionCS <- predict(RF.CS, newdata=testSet)
testSet$PredictionCSFM <- predict(RF.CS$finalModel, newdata=testSet)
testSetCS$Prediction <- predict(RF, newdata=testSetCS)
testSetCS$PredictionFM <- predict(RF$finalModel, newdata=testSetCS)
testSetCS$PredictionCS <- predict(RF.CS, newdata=testSetCS)
testSetCS$PredictionCSFM <- predict(RF.CS$finalModel, newdata=testSetCS)