I have some test data and labels:
testZ = [0.25, 0.29, 0.62, 0.27, 0.82, 1.18, 0.93, 0.54, 0.78, 0.31, 1.11, 1.08, 1.02];
testY = [1 1 1 1 1 2 2 2 2 2 2 2 2];
I then sort them:
[sZ, ind] = sort(testZ); %%Sorts Z, and gets indexes of Z
sY = testY(ind); %%Sorts Y by index
[N, n] = size(testZ');
This will then give the sorted Y data. At each element of the sorted Y data, I want to classify each point to the left as being of type 1 and everything to the right being class 2; This will then be repeated for every point of the data. How can I do this and find out for each element the variables:
- TP(true positive) - the elements correctly marked as 1
- FP(false positive) - the elements incorrectly marked as 1
- TN(true negative) - the elements correctly marked as 2
- FN(false negatives) - the elements incorrectly marked as 2
The purpose of this is so that I can create an ROC curve for the classifier as part of some school work.
Here is the code for plotting ROC and finding AUC value:
Above code is the modified version given on http://www.dcs.gla.ac.uk/~srogers/firstcourseml/matlab/chapter5/svmroc.html
You can loop over the points and then use logical indexing and element-wise Boolean operators to get most of what you want.
I didn't run this, so you might need some tweaks, but this should get you most of the way.