Jump to content

calculating true and false positives and negatives


bolter

Recommended Posts

Ok I guess this is more a algorithm problem than a php problem, but still I hope someone can help me.

I'm trying to write some code that starting from two arrays containing observed and expected values will calculate true and false positive and negative rates of a certain event.

Let's say I have 30 events and 5 of them are really red while 25 are blue. (each event is identified by an unique id i.e. number)

An observer is required to evaluate the 30 events and answer if they are red or blue, their answer (only if blue if stored in the observed array - in the form of a position id)

So in the end I have one array that has the observed red events i.e. 4 56 78 44 90 and the expected array with the actual red events i.e. 4 78 33 34

In this case my true positive would be 2 (4 and 78 that are both in the observed and the expected), my false positive would be 3 (observed but not expected), my false negative 2 (expected but not observed) and my true negative 23 (not expected and not observed, obtained substracting the previous three from the total number of events)

How can I calculate this four values using PHP, I thought it was easier but as I started to program it I realized I didn't know where to go

Thanks to all!

Link to comment
Share on other sites

$truePositive  = count(array_intersect($redObserved,$redExpected));
$falsePositive = count(array_diff($redObserved, $redExpected));
$falseNegative = count(array_diff($redExpected, $redObserved));
$trueNegative  = $totalEvents - ($truePositive + $falsePositive + $falseNegative);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.