November 2017
Beginner
286 pages
8h 13m
English
There is now a function able to train our ensemble classifier using AdaBoost, but we also need a function to make the actual predictions. This function will take in the output list produced by our training function, AdaBoostNN(), along with a test dataset.
This function is AdaBoostNN.predict() and it is shown as follows:
AdaBoostNN.predict <- function(ada_model, test_data) {
models <- ada_model$models
alphas <- ada_model$alphas
prediction_matrix <- sapply(models, function (x)
as.numeric(predict(x, test_data, type = "class")))
weighted_predictions <- t(apply(prediction_matrix, 1,
function(x) mapply(function(y, z) y * z, x, alphas)))
final_predictions <- apply(weighted_predictions, 1, function(x) sign(sum(x))) return(final_predictions) ...Read now
Unlock full access