The reason behind the command '[label, score] = predict(Mdl1,pX)' not returning scores as probability estimates is because the 'LogitBoost' algorithm used in the model does not treat scores as probabilistic estimates. Instead, the score represents the confidence of a classification into a class, higher, being more confidence.This is explained in the documentation link below:
https://www.mathworks.com/help/stats/compactclassificationensemble.predict.html#bvciha4
If you would like to get probabilistic estimate for scores, you may consider one of two options:1) You can set the 'ScoreTransform' name-value pair in the 'fitcensemble' to 'logit'. This name-value pair transforms the score to probabilistic estimates.https://www.mathworks.com/help/stats/fitcensemble.html#bvcj_s0-1_sep_shared-ScoreTransformUsing predict on the model then returns scores as probability values for each class.For example:
MdlFinal = fitcensemble(X,Y,'NumLearningCycles',idxNumTrees,...
'Learners',tFinal,'LearnRate',learnRate(idxLR),'ScoreTransform','logit')
>> [~,scores] = predict(MdlFinal,X)
scores =
0.0360 0.9640
0.8054 0.1946
0.0278 0.9722
...
2) Setting the 'Method' name-value pair of 'fitcensemble' to 'Bag'.As mentioned in the documentation link here , the 'Bag' algorithm returns scores as probability values.The documentation link for 'Method' name-value pair can be found here:
- Run below command in MATLAB 2017a for documentation:
>> web(fullfile(docroot, 'stats/fitcensemble.html'))
Or for latest release documentation please refer to:https://www.mathworks.com/help/stats/fitcensemble.html