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!

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.