Split your dataset into a training set and a testing set
Train your SVM using the training set only
Evaluate the testing set using the trained svm model
Compare the pre-known labels L of your testing set with the output of the svm O (step 3)
We want the label matching the output. But we distinguish further between true positive (TP) and true negative (TN). Also, if the label does not match the output, we distinguish further between false positive (FP) and false negative (FN).
You start with TP = TN = FP = FN = 0. Now you go through your testing set and increment TP, if your label matches and is positive. You increment TN if your label matches and is negative, a.s.o.
At the end you have a value for TP, TN, FP, and FN (the so called confusion matrix). This is only one single value in the ROC plot. Look at http://en.wikipedia.org/wiki/Receiver_operating_characteristic to see how to calculate the TPR and FPR for the ROC.
But the svm output is calculated by y = sgn(w^T - b). If you vary the bias b (which is the offset of the hyperplane) and redo step 3 to 7 you get more and more points on the ROC plot
This is quite inefficient because you have to reevaluate the svm model each time. And who is gonna tell you the correct value for b?
If you evaluate your testing set with the svm, simply don't use the signum but instead evaluate y = w^T * x - b (most svm implementation provide only this floating point value anyhow). Now you need to threshold this value to receive a label. And each possible threshold will provide you with a single point in the ROC plot. And who tells you the threshold? Just use every single value your svm produced.
Instead of manually splitting the dataset into a training and a testing set you might want to consider k-fold crossvalidation: http://en.wikipedia.org/wiki/Cross-validation_(statistics)
from your question there is not enough detail to know what is that you would like to do.
I assume that your problem is that SVM is a binary classifier which return 0 or 1, and you cannot directly use this kind of output to compute your ROC. If this is the case, one solution can be to take the distance of each of your point to the hyperplane and transform this into a predicted probability by using a binary logistic model. The you can use the predicted probabilities returned by this model to do ROC analysis. I attach an article by Platt for reference. Hope this helps. Costanzo
Split your dataset into a training set and a testing set
Train your SVM using the training set only
Evaluate the testing set using the trained svm model
Compare the pre-known labels L of your testing set with the output of the svm O (step 3)
We want the label matching the output. But we distinguish further between true positive (TP) and true negative (TN). Also, if the label does not match the output, we distinguish further between false positive (FP) and false negative (FN).
You start with TP = TN = FP = FN = 0. Now you go through your testing set and increment TP, if your label matches and is positive. You increment TN if your label matches and is negative, a.s.o.
At the end you have a value for TP, TN, FP, and FN (the so called confusion matrix). This is only one single value in the ROC plot. Look at http://en.wikipedia.org/wiki/Receiver_operating_characteristic to see how to calculate the TPR and FPR for the ROC.
But the svm output is calculated by y = sgn(w^T - b). If you vary the bias b (which is the offset of the hyperplane) and redo step 3 to 7 you get more and more points on the ROC plot
This is quite inefficient because you have to reevaluate the svm model each time. And who is gonna tell you the correct value for b?
If you evaluate your testing set with the svm, simply don't use the signum but instead evaluate y = w^T * x - b (most svm implementation provide only this floating point value anyhow). Now you need to threshold this value to receive a label. And each possible threshold will provide you with a single point in the ROC plot. And who tells you the threshold? Just use every single value your svm produced.
Instead of manually splitting the dataset into a training and a testing set you might want to consider k-fold crossvalidation: http://en.wikipedia.org/wiki/Cross-validation_(statistics)
Costanzo is correct. You will find software to do this in R (which is open source), in particular the kernlabs package by Alexandros Karatzoglou, Alex Smola and Kurt Hornik. See http://cran.r-project.org/web/packages/kernlab/vignettes/kernlab.pdf. This software is very high quality, Smola is a leading researcher in maximum margin methods.
Thank you all. Mr.Costanzo my problem is binary and need to compute ROC for svm applied I am not sure that what should I use svm accuracy or error rate to compute ROC. Mr.Frerek I have done ROC computation on each step /iteration but ROC plot is very non-obvious resembling a stair case ascended.
ROC curve analysis does not use accuracy or error rate. An ROC curve plots sensitivity (y axis) versus 1-specificity (x axis). You have one point for each value that you set as the threshold on your measurement. Your measurement could be the predicted probabilities if you use the approach mentioned above. As Thomas explained above, there are free packages that can help you to do this in R. Or you can use other software like SPSS if you are more familiar with it. I would suggest you do some more reading about ROC curve analysis before going any further. Costanzo
it seems that you are more than half way through. As Constanzo pointed out. ROC plots the false positive rate vs. true positive rate, or sensitivity vs. 1-specificity (which is the same). This is clearly mentioned in the link: http://en.wikipedia.org/wiki/Receiver_operating_characteristic
I recommend you to read this since you might want to interpret your classification results afterwards. A good knowledge about the different performance measurements is crucial.
Because various suggestions have been made according to implementations using R or Matlab, could you tell us which platform you are using?
As it is a fairly old thread, I assume you've already solved the problem. However, if not, you might find it useful to have look at "perfcurve" documntation in Matlab. Hope it helps.
Thank you. Yes it is old one but I still cudn't solve it, as I have older version of matlab 2013. And the perfcurve is in matlab 2014 which I cudnt get till now.
Hi Sheema please find the attached file. Copy and paste the contents into a .m file in Matlab and save it as p.e.r.f.c.u.r.v.e.m. Then you can use it. Hope it helps.