Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to calculate roc curves?

I write a classifier (Gaussian Mixture Model) to classify five human actions. For every observation the classifier compute the posterior probability to belong to a cluster.

I want to valutate the performance of my system parameterized with a threshold, with values from 0 to 100. For every threshold values, for every observation, if the probability of belonging to one of cluster is greater than threshold I accept the result of the classifier otherwise I discard it.

For every threshold values I compute the number of true-positive, true-negative, false-positive, false-negative.

Than I compute the two function: sensitivity and specificity as

sensitivity = TP/(TP+FN);

specificity=TN/(TN+FP);

In matlab:

plot(1-specificity,sensitivity);

to have the ROC curve. But the result isn't what I expect.

This is the plot of the functions of discards, errors, corrects, sensitivity and specificity varying the threshold of one action.

This is the plot of the functions of discards, errors, corrects, sensitivity and specificity varying the threshold

This is the plot of ROC curve of one action This is the plot of ROC curve

This is the stem of ROC curve for the same action enter image description here

I am wrong, but i don't know where. Perhaps I do wrong the calculating of FP, FN, TP, TN especially when the result of the classifier is minor of the threshold, so I have a discard. What I have to incremente when there is a discard?

like image 411
Mario Lepore Avatar asked Oct 19 '12 18:10

Mario Lepore


People also ask

How do you calculate ROC curve in Excel?

The ROC curve can then be created by highlighting the range F7:G17 and selecting Insert > Charts|Scatter and adding the chart and axes titles (as described in Excel Charts). The result is shown on the right side of Figure 1. The actual ROC curve is a step function with the points shown in the figure.

How do you calculate ROC AUC?

The AUC for the ROC can be calculated using the roc_auc_score() function. Like the roc_curve() function, the AUC function takes both the true outcomes (0,1) from the test set and the predicted probabilities for the 1 class. It returns the AUC score between 0.0 and 1.0 for no skill and perfect skill respectively.

How is ROC curve cutoff value calculated?

No surprise, another common criterion for choosing the most appropriate cut-off value is selecting the point on the ROC curve with the minimum distance from the left-upper corner of the unit square (8, 15, 16).


1 Answers

Background

I am answering this because I need to work through the content, and a question like this is a great excuse. Thank you for the good opportunity.

I use data from the built-in fisher iris data: http://archive.ics.uci.edu/ml/datasets/Iris

I also use code snippets from the Mathworks tutorial on the classification, and for plotroc

  • http://www.mathworks.com/products/demos/statistics/classdemo.html
  • http://www.mathworks.com/help/nnet/ref/plotroc.html?searchHighlight=plotroc

Problem Description

There is clearer boundary within the domain to classify "setosa" but there is overlap for "versicoloir" vs. "virginica". This is a two dimensional plot, and some of the other information has been discarded to produce it. The ambiguity in the classification boundaries is a useful thing in this case.

%load data
load fisheriris

%show raw data
figure(1); clf
gscatter(meas(:,1), meas(:,2), species,'rgb','osd');
xlabel('Sepal length');
ylabel('Sepal width');
axis equal
axis tight
title('Raw Data')

display of the data

Analysis

Lets say that we want to determine the bounds for a linear classifier that defines "virginica" versus "non-virginica". We could look at "self vs. not-self" for other classes, but they would have their own

So now we make some linear discriminants and plot the ROC for them:

%load data
load fisheriris
load iris_dataset

irisInputs=meas(:,1:2)';
irisTargets=irisTargets(3,:);

ldaClass1 = classify(meas(:,1:2),meas(:,1:2),irisTargets,'linear')';
ldaClass2 = classify(meas(:,1:2),meas(:,1:2),irisTargets,'diaglinear')';
ldaClass3 = classify(meas(:,1:2),meas(:,1:2),irisTargets,'quadratic')';
ldaClass4 = classify(meas(:,1:2),meas(:,1:2),irisTargets,'diagquadratic')';
ldaClass5 = classify(meas(:,1:2),meas(:,1:2),irisTargets,'mahalanobis')';

myinput=repmat(irisTargets,5,1);
myoutput=[ldaClass1;ldaClass2;ldaClass3;ldaClass4;ldaClass5];
whos
plotroc(myinput,myoutput)

The result is shown in the following, though it took deleting repeat copies of the diagonal:

enter image description here

You can note in the code that I stack "myinput" and "myoutput" and feed them as inputs into the "plotroc" function. You should take the results of your classifier as targets and actuals and you can get similar results. This compares the actual output of your classifier versus the ideal output of your target values. Those are the input to plotroc.

So this will give you "built-in" ROC, which is useful for quick work, but does not make you learn every step in detail.

Questions you can ask at this point include:

  • which classifier is best? How do I determine what best is in this case?
  • What is the convex hull of the classifiers? Is there some mixture of classifiers that is more informative than any pure method? Bagging perhaps?
like image 195
EngrStudent Avatar answered Oct 02 '22 06:10

EngrStudent