module Data.HInduce.Classifier
( module Data.HInduce.Classifier.Class
, confusion, confusion'
, absConfusion, absConfusion'
) where
import Control.Arrow
import Data.HInduce.Classifier.Class
import Data.List.HIUtils
import Data.Ratio
import Text.Layout
newtype Confusion label = Confusion { fromConfusion :: [((label, label), Int)] }
deriving (Eq, Ord, Read, Show)
confusion :: (Classifier classifier attributes label,
Ord label,
Fractional f) =>
classifier -> [(attributes, label)] -> [((label, label), f)]
confusion cl db = map (second (fromRational . (% s) . fromIntegral)) absconf
where absconf = absConfusion cl db
s = fromIntegral . sum . map snd $ absconf
absConfusion :: ( Classifier classifier attributes label
, Ord label
) =>
classifier -> [(attributes, label)] -> [((label, label), Int)]
absConfusion cl = count . aggregate . toLabelpairs
where toLabelpairs = map (snd &&& classify cl . fst)
count = map (head &&& length)
confusion' :: ( Classifier classifier attributes label
, Ord label, Show label
) =>
classifier -> [(attributes, label)] -> Table label label Double
confusion' cl db = Table "Confusion Matrix" ("Actual", "Predicted") $ confusion cl db
absConfusion' :: ( Classifier classifier attributes label
, Ord label, Show label
) =>
classifier -> [(attributes, label)] -> Table label label Int
absConfusion' cl db = Table "Absolute Confusion Matrix" ("Actual","Predicted") $ absConfusion cl db