Posterior probability for cross-validated fitcecoc model

조회 수: 4 (최근 30일)
Noam
Noam 2024년 1월 22일
댓글: Noam 2024년 1월 24일
I'm trying to get posterior probabilities, rather than prediction scores from a cross-validated fitcecoc model using the following
t = templateSVM('Standardize',true);
Modelall = fitcecoc(X,Y,'Learners',t,'ClassNames', unique(stimNum),'Options',opts,'FitPosterior', true);
[label,~,~,Posterior] = resubPredict(Modelall);
However, when cross-validation is turned on
Modelall = fitcecoc(X,Y,'Learners',t,'ClassNames', unique(stimNum),'Options',opts,'FitPosterior', true, 'CrossVal','on','KFold' ,10);
I get the following error:
"Incorrect number or types of inputs or outputs for function 'resubPredict'."
is there any way to get the prediction probability of a multiclass cross-validated classifier analogous to a binary SVM (using 'fitSVMPosterior')?
Thanks in advance

채택된 답변

Aditya
Aditya 2024년 1월 24일
Hi Noam,
When you have a cross-validated error-correcting output codes (ECOC) model created with fitcecoc and the 'CrossVal','on' option, you cannot use resubPredict to get the predictions or posterior probabilities. Instead, you should use kfoldPredict to obtain the cross-validated predictions and posterior probabilities. Here's how you can do it:
% Cross-validated ECOC model
opts = statset('UseParallel', false); % Set 'UseParallel' to true if you want to use parallel computing
Modelall = fitcecoc(X, Y, 'Learners', t, 'ClassNames', unique(Y), ...
'Options', opts, 'FitPosterior', true, 'CrossVal', 'on', 'KFold', 10);
% Get the predicted labels and posterior probabilities for each fold
[label,~,~,Posterior] = kfoldPredict(Modelall);
The kfoldPredict function will return the cross-validated predicted labels in label and the posterior probabilities in Posterior. The syntax label,~,~,Posterioris used to ignore the second and third output arguments from kfoldPredict and only obtain the labels and posterior probabilities.
For additional examples and documentation, you can refer to the official MathWorks documentation page for fitcecoc” function, which includes an example of using kfoldPredict with a cross-validated ECOC model.
Hope this helps you to resolve the issue!

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Classification Ensembles에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by