accuracy can work on probs now
This commit is contained in:
parent
ff8ec8880e
commit
cea084c789
@ -1,5 +1,5 @@
|
||||
name: geval
|
||||
version: 0.5.3.0
|
||||
version: 0.5.4.0
|
||||
synopsis: Machine learning evaluation tools
|
||||
description: Please see README.md
|
||||
homepage: http://github.com/name/project
|
||||
|
@ -47,6 +47,7 @@ import Data.Text
|
||||
import Data.Text.Read as TR
|
||||
import Control.Applicative
|
||||
import Control.Exception
|
||||
import Text.Read (readMaybe)
|
||||
import Control.Conditional (unlessM, whenM)
|
||||
import qualified System.Directory as D
|
||||
import System.Posix
|
||||
@ -312,7 +313,20 @@ gevalCore' BLEU _ = gevalCoreWithoutInput (Right . Prelude.map Prelude.words . D
|
||||
| otherwise = exp (1.0 - (r /. c))
|
||||
|
||||
gevalCore' Accuracy _ = gevalCoreWithoutInput (Right . strip) (Right . strip) hitOrMiss averageC id
|
||||
where hitOrMiss (x,y) = if x == y then 1.0 else 0.0
|
||||
where hitOrMiss (exp,got) = if (normalizeProbForAccuracy exp got) == exp then 1.0 else 0.0
|
||||
-- if the expected value is 0 or 1 treat values between 0.0 and 1.0 as probabilities
|
||||
-- for the positive outcome
|
||||
normalizeProbForAccuracy :: Text -> Text -> Text
|
||||
normalizeProbForAccuracy exp got
|
||||
| exp == (pack "1") = case tryReadingAsFloat got of
|
||||
Just p -> if p >= 0.5 && p <= 1.0 then exp else got
|
||||
Nothing -> got
|
||||
| exp == (pack "0") = case tryReadingAsFloat got of
|
||||
Just p -> if p < 0.5 && p >= 0.0 then exp else got
|
||||
Nothing -> got
|
||||
| otherwise = got
|
||||
tryReadingAsFloat :: Text -> Maybe Float
|
||||
tryReadingAsFloat = readMaybe . unpack
|
||||
|
||||
gevalCore' (FMeasure beta) _ = gevalCoreWithoutInput outParser outParser getCount countAgg (fMeasureOnCounts beta)
|
||||
where outParser = detected <=< (getValue . TR.double)
|
||||
|
@ -53,6 +53,8 @@ main = hspec $ do
|
||||
describe "Accuracy" $ do
|
||||
it "simple example" $
|
||||
runGEvalTest "accuracy-simple" `shouldReturnAlmost` 0.6
|
||||
it "with probs" $
|
||||
runGEvalTest "accuracy-probs" `shouldReturnAlmost` 0.4
|
||||
describe "F-measure" $ do
|
||||
it "simple example" $
|
||||
runGEvalTest "f-measure-simple" `shouldReturnAlmost` 0.57142857
|
||||
|
10
test/accuracy-probs/accuracy-probs-solution/test-A/out.tsv
Normal file
10
test/accuracy-probs/accuracy-probs-solution/test-A/out.tsv
Normal file
@ -0,0 +1,10 @@
|
||||
1
|
||||
0
|
||||
foo
|
||||
0
|
||||
-1.5
|
||||
0.7
|
||||
1.001
|
||||
0.3
|
||||
0.45
|
||||
0.45
|
|
1
test/accuracy-probs/accuracy-probs/config.txt
Normal file
1
test/accuracy-probs/accuracy-probs/config.txt
Normal file
@ -0,0 +1 @@
|
||||
--metric Accuracy
|
10
test/accuracy-probs/accuracy-probs/test-A/expected.tsv
Normal file
10
test/accuracy-probs/accuracy-probs/test-A/expected.tsv
Normal file
@ -0,0 +1,10 @@
|
||||
1
|
||||
0
|
||||
0
|
||||
1
|
||||
0
|
||||
1
|
||||
1
|
||||
1
|
||||
1
|
||||
0
|
|
Loading…
Reference in New Issue
Block a user