fix(recall, precision): little bug in calculations
feat(fmeasure): calculate fmeasure using recall and precision
This commit is contained in:
parent
812717522e
commit
76e7e7faef
@ -24,6 +24,11 @@ module Main
|
||||
let showResults (c, r) = putStrLn (classes !! c ++ " ~ " ++ classes !! r)
|
||||
mapM_ showResults results
|
||||
|
||||
let showAccuracy (c, r) =
|
||||
print $ genericLength (filter (\(h, j) -> h == j && h == c) results) / genericLength results
|
||||
mapM_ showAccuracy results
|
||||
|
||||
putStrLn $ "Recall: " ++ show (recall results) ++ "%"
|
||||
putStrLn $ "Precision: " ++ show (precision results) ++ "%"
|
||||
putStrLn $ "F Measure: " ++ show (fmeasure (precision results) (recall results))
|
||||
putStrLn $ "Accuracy: " ++ show (accuracy results) ++ "%"
|
||||
|
@ -9,6 +9,7 @@ module Sibe.NaiveBayes
|
||||
accuracy,
|
||||
precision,
|
||||
recall,
|
||||
fmeasure,
|
||||
)
|
||||
where
|
||||
import Data.List
|
||||
@ -74,24 +75,27 @@ module Sibe.NaiveBayes
|
||||
let correct = filter (uncurry (==)) results
|
||||
in round $ genericLength correct / genericLength results * 100
|
||||
|
||||
recall :: [(Int, Int)] -> Int
|
||||
recall :: [(Int, Int)] -> Double
|
||||
recall results =
|
||||
let classes = ordNub (map fst results)
|
||||
s = sum (map rec classes) / genericLength results
|
||||
in round $ s * 100
|
||||
s = sum (map rec classes) / genericLength classes
|
||||
in s * 100
|
||||
where
|
||||
rec a =
|
||||
let t = genericLength $ filter (\(c, r) -> c == r && c == a) results
|
||||
y = genericLength $ filter (\(c, r) -> c == a) results
|
||||
in t / y
|
||||
|
||||
precision :: [(Int, Int)] -> Int
|
||||
precision :: [(Int, Int)] -> Double
|
||||
precision results =
|
||||
let classes = ordNub (map fst results)
|
||||
s = sum (map prec classes) / genericLength results
|
||||
in round $ s * 100
|
||||
s = sum (map prec classes) / genericLength classes
|
||||
in s * 100
|
||||
where
|
||||
prec a =
|
||||
let t = genericLength $ filter (\(c, r) -> c == r && c == a) results
|
||||
y = genericLength $ filter (\(c, r) -> r == a) results
|
||||
in t / y
|
||||
|
||||
fmeasure :: Double -> Double -> Double
|
||||
fmeasure r p = (2 * p * r) / (p + r)
|
||||
|
Loading…
Reference in New Issue
Block a user