function res = precrec(ytrue, ypred, drawgraphs,L) % PRECREC : does precision-recall analysis for binary classification % ytrue is a N-element vector with the true labels % the classes in ytrue are integers A and B , where A res.thresh(i))) = 1; [cm,nc,prec,rec,fscore]=getcm(YTRUE,YPRED,[0 1]); res.cm{i} = cm; res.ac(i) = nc/N; res.wac(i) = mean(prec); res.precA(i) = prec(1); res.precB(i) = prec(2); res.recA(i) = rec(1); res.recB(i) = rec(2); res.FA(i) = fscore(1); res.FB(i) = fscore(2); end if drawgraphs figure; subplot(2,3,1); plot(res.precA,res.recA,'r-',res.precA,res.recA,'bo'); xlabel('precision'); ylabel('recall'); title(sprintf('precision/recall for class %d',classes(1))); axis([0 1 0 1]); subplot(2,3,2); plot(res.precB,res.recB,'r-',res.precB,res.recB,'bo'); xlabel('precision'); ylabel('recall'); title(sprintf('precision/recall for class %d',classes(2))); axis([0 1 0 1]); subplot(2,3,3); plot(res.FA,res.FB,'r-',res.FA,res.FB,'bo'); xlabel(sprintf('F-score for class %d',classes(1))); ylabel(sprintf('F-score for class %d',classes(2))); title('Fscores'); axis([0 1 0 1]); subplot(2,3,4); plot(res.precA,res.precB,'r-',res.precA,res.precB,'bo'); xlabel(sprintf('precision for class %d',classes(1))); ylabel(sprintf('precision for class %d',classes(2))); title('Precision'); subplot(2,3,5); plot(1-res.precA,res.precB,'r-',1-res.precA,res.precB ,'bo'); xlabel(sprintf('1-True class%d rate',classes(1))); ylabel(sprintf('True class%d rate',classes(2))); title('ROC curve'); axis([0 1 0 1]); subplot(2,3,6); plot(res.thresh,res.wac,'r-',res.thresh,res.ac,'r--'); legend('weighted','unweighted'); hold on; plot(res.thresh,res.wac,'bo'); xlabel('threshold'); ylabel('accuracy'); title('accuracy (un/weighted by 1/class prob)'); axis([min(res.thresh) max(res.thresh) 0 1]); hold off; end