module Statistics.PerformanceMetrics where
import Control.Monad.Instances
import Statistics.ConfusionMatrix
sensitivity :: ConfusionMatrix -> WrappedDouble
sensitivity ConfusionMatrix{..} = do
tp <- tp
fn <- fn
if tp>0
then Right $ tp / (tp+fn)
else Right 0
specificity :: ConfusionMatrix -> WrappedDouble
specificity ConfusionMatrix{..} = do
tp <- tp
fp <- fp
if tp>0
then Right $ tp / (tp+fp)
else Right 0
ppv :: ConfusionMatrix -> WrappedDouble
ppv ConfusionMatrix{..} = do
tp <- tp
fp <- fp
if tp>0
then Right $ tp / (tp+fp)
else Right 0
mcc :: ConfusionMatrix -> WrappedDouble
mcc ConfusionMatrix{..} = do
tp <- tp
tn <- tn
fp <- fp
fn <- fn
let d' = (tp+fp) * (tp+fn) * (tn+fp) * (tn+fn)
let d = if d'==0 then 1 else sqrt d'
return $ (tp*tn fp*fn) / d
fmeasure :: ConfusionMatrix -> WrappedDouble
fmeasure ConfusionMatrix{..} = do
tp <- tp
fp <- fp
fn <- fn
if tp>0
then Right $ 2*tp / (2*tp + fp + fn)
else Right 0