How to do a ROC analysis using Matlab build-in SVM (Not LibSVM)
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Aaronne
el 21 de Mzo. de 2013
Respondida: Mehrdad Heydarzadeh
el 10 de Ag. de 2016
Hi all,
Just wondering anyone knows how to do a ROC analysis using Matlab build-in SVM? This question has been asked by millions of times on the web, but no answer.
svmStruct = svmtrain(featureSelcted, groundTruthGroup, 'Kernel_Function', 'rbf', 'Method', 'QP');
svmClassified = svmclassify(svmStruct,featureSelcted);
% Predict resubstitution response of SVM classifier
SVMScore ???
% Fit probabilities for scores
[FPR, TPR, Thr, AUC, OPTROCPT] = perfcurve(groundTruth(:,1), SVMScore(:,1), 1);
Essentially, we need a function to get the '*scores*' of the SVM classifier (SVMScore). Thanks!
A.
0 comentarios
Respuesta aceptada
Ilya
el 21 de Mzo. de 2013
Well, there is an answer here http://www.mathworks.com/matlabcentral/answers/64475-does-anybody-have-expertise-with-matlab-svm-classifier, with a reference to another thread. I am collecting all the pieces in one place.
Assume your class labels are -1 and +1, assume that you have trained with 'autoscale' set to true by default, let svm be the struct for the trained SVM model, and let Xnew be the new data for which you need to compute the soft scores.
shift = svm.ScaleData.shift;
scale = svm.ScaleData.scaleFactor;
Xnew = bsxfun(@plus,Xnew,shift);
Xnew = bsxfun(@times,Xnew,scale);
sv = svm.SupportVectors;
alphaHat = svm.Alpha;
bias = svm.Bias;
kfun = svm.KernelFunction;
kfunargs = svm.KernelFunctionArgs;
f = kfun(sv,Xnew,kfunargs{:})'*alphaHat(:) + bias;
f = -f; % flip the sign to get the score for the +1 class
Then call perfcurve(true_labels,f,1).
7 comentarios
Tahir
el 8 de Mayo de 2015
Hi, i just use the code ...but i have confusion about the line
f = -f; % flip the sign to get the score for the +1 class
why this flipping?? i use labels 0 and 1...still i should flip the f.??
Farag Zbeda
el 3 de Jun. de 2015
Hi Ilya
What do yo mean by true_labels when calling perfcurve(true_labels,f,1)? I guess they are the test instances labels. If so, how to calculate them?
Thanks
Faraj
Más respuestas (1)
Mehrdad Heydarzadeh
el 10 de Ag. de 2016
Hi Aaronne, It seems that your problem has been answered. But there is a shorter way of doing that using Matlab functions. Just have a look at the second example in following link: http://www.mathworks.com/help/stats/perfcurve.html
0 comentarios
Ver también
Categorías
Más información sobre Discriminant Analysis en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!