How to Display ROC plot
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi guys, i'm using 10 times k fold cross validation for the implementation of machine learning.. i already display the confusion matrix, but i would like to display the ROC plot
Here's the example of my code..
function NB=jNB(feat,label,Dist,kfold)
switch Dist
case'n'; Dist='normal';
case'k'; Dist='kernel';
end
rng('default');
% Divide data into k-folds
fold=cvpartition(label,'kfold',kfold);
% Pre
pred2=[]; ytest2=[]; Afold=zeros(kfold,1);
% Naive Bayes start
for i=1:kfold
% Call index of training & testing sets
trainIdx=fold.training(i); testIdx=fold.test(i);
% Call training & testing features and labels
xtrain=feat(trainIdx,:); ytrain=label(trainIdx);
xtest=feat(testIdx,:); ytest=label(testIdx);
% Training the model
Model=fitcnb(xtrain,ytrain,'Distribution',Dist);
% Perform testing
Pred0=predict(Model,xtest); %A=size(Pred0,1);
% Confusion matrix
con=confusionmat(ytest,Pred0);
disp(['The Confusion matrix for fold number ' num2str(i)])
disp(con)
% Accuracy for each fold
Afold(i)=(sum(diag(con))/sum(con(:)))*100;
%Sensitivity for each fold
TP=con(1);
TP_FN=sum(con(:,1));
sensitivity=(TP/TP_FN)*100;
sensitivityAll(i)=(TP/TP_FN)*100;
disp(['Classification Sensitivity For Each Fold(NB) ' num2str(i)])
disp(sensitivity)
%Specificity for each fold
TN=con(4);
TN_FP=sum(con(:,2));
specificity=(TN/TN_FP)*100;
specificityAll(i)=(TN/TN_FP)*100;
disp(['Classification Specificity For Each Fold(NB) ' num2str(i)])
disp(specificity)
% Store temporary
pred2=[pred2(1:end);Pred0]; ytest2=[ytest2(1:end);ytest];
end
%Sensitivity Average
bcc=mean(sensitivityAll);
disp('Classification Sensitivity Average(NB)')
disp(bcc)
%Specificity Average
ccc=mean(specificityAll);
disp('Classification Sensitivity Average(NB)')
disp(ccc)
% Overall confusion matrix
confmat=confusionmat(ytest2,pred2);
% Average accuracy over k-folds
acc=mean(Afold);
% Store results
NB.fold=Afold; NB.acc=acc; NB.conf=con; NB.con=confmat; NB.bcc=bcc; NB.ccc=ccc;
fprintf('\n Classification Accuracy For Each Fold(NB): %g %%',Afold);
fprintf('\n Classification Average Accuracy (NB): %g %%',acc);
fprintf('\n Classification Average Sensitivity (NB): %g %%',bcc);
fprintf('\n Classification Average Specificity (NB): %g %%',ccc);
fold
disp(NB.conf);
end
with that code i can display all confusion matrix. but i want to display the ROC plot based on my code. i do really appreciate your help and your answer.. Thank You
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Naive Bayes에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!