In addition to predicting the class labels, is it possible to return the expectation of each observation in new data when predicting?
library(caret)
knnFit <- train(Species ~ ., data = iris, method = "knn",
trControl = trainControl(method = "cv", classProbs = TRUE))
x <- predict(knnFit, newdata = iris)
Returns a vector of the predicted classes.
str(x)
Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1 1 1 1 1 ...
If I want the probabilities:
x <- predict(knnFit, newdata = iris, type = "prob")
> head(x)
setosa versicolor virginica
1 1 0 0
2 1 0 0
3 1 0 0
4 1 0 0
5 1 0 0
6 1 0 0
Is it possible to have caret return both the predictions and the probabilities? I know I can calculate by taking max.col of probabilities version but I wondered if there's a built in way to get both?