1function [pred, scores] = predictEnsemble(learners, X)
2% This function
is a custom predict function
for ensembles
3% of decision trees trained
using either umrbBagging or
4% smoteBagging.
"learners" is a cell arry of MATLAB decision
5% tree objects, and X
is an N x M array, where N
is the number
6% of test instances, and M
is the number of features used to
12 preCombinedScores = cell2mat(cellfun(@testPredict, learners, 'UniformOutput
', false));
13 numLearners = length(learners);
15 scores = zeros(numRows, size(preCombinedScores, 2));
16 pred = zeros(numRows, 1);
18 scores(i, :) = mean(preCombinedScores(i:numRows:i+(numLearners-1)*numRows, :));
19 highestIdx = find(scores(i, :) == max(scores(i, :)));
20 pred(i) = highestIdx(randi(length(highestIdx))); % Break ties using random choice
23 function scores = testPredict(learner)
24 [~, scores] = learner.predict(X);