Implementing the binary outcome (0 or 1) toy example from the Super Learner documentation produces a vector of values between 0 and 1 for the SL.predict
object. My understanding is that in order to produce binary predictions, the user needs to reclassify these values to either 0 or 1. For example, if the model produced a prediction greater than 0.5, reclassify as 1. Otherwise, reclassify as 0.
Is my understanding correct? If not, some advice on how to interpret these results would be greatly appreciated.
Following is the code for the toy example and the resulting SL.predict
object:
###Toy example
# binary outcome
set.seed(1)
N <- 200
X <- matrix(rnorm(N*10), N, 10)
X <- as.data.frame(X)
Y <- rbinom(N, 1, plogis(.2*X[, 1] + .1*X[, 2] - .2*X[, 3] +
.1*X[, 3]*X[, 4] - .2*abs(X[, 4])))
SL.library <- c("SL.glmnet", "SL.glm", "SL.knn", "SL.gam", "SL.mean")
# least squares loss function
test.NNLS <- SuperLearner(Y = Y, X = X, SL.library = SL.library,
verbose = TRUE, method = "method.NNLS", family = binomial())
# check some prediction values
head(test.NNLS$SL.predict)
[,1]
1 0.3391220
2 0.3573499
3 0.4086673
4 0.4206464
5 0.4609441
6 0.3731298
>