2016-07-29 11:46:44 +00:00
|
|
|
module Main
|
|
|
|
where
|
|
|
|
import Sibe
|
|
|
|
import Sibe.NaiveBayes
|
|
|
|
import Text.Printf
|
|
|
|
import Data.List
|
|
|
|
import Data.Maybe
|
|
|
|
import Debug.Trace
|
2016-07-29 13:25:59 +00:00
|
|
|
import Data.List.Split
|
2016-07-29 11:46:44 +00:00
|
|
|
|
|
|
|
main = do
|
2016-07-29 13:25:59 +00:00
|
|
|
dataset <- readFile "examples/doc-classifier-data/data-reuters"
|
|
|
|
test <- readFile "examples/doc-classifier-data/data-reuters-test"
|
2016-07-29 11:46:44 +00:00
|
|
|
|
2016-07-29 13:25:59 +00:00
|
|
|
classes <- map (filter (/= ' ')) . lines <$> readFile "examples/doc-classifier-data/data-classes"
|
2016-07-29 11:46:44 +00:00
|
|
|
|
|
|
|
let intClasses = [0..length classes - 1]
|
|
|
|
documents = createDocuments classes dataset
|
|
|
|
testDocuments = createDocuments classes test
|
2016-07-30 12:22:34 +00:00
|
|
|
devTestDocuments = take 20 testDocuments
|
2016-07-29 11:46:44 +00:00
|
|
|
nb = initialize documents
|
|
|
|
|
2016-07-29 13:25:59 +00:00
|
|
|
results = map (\(Document text c) -> (c, determine text nb intClasses documents)) testDocuments
|
2016-07-30 12:22:34 +00:00
|
|
|
-- results = map (\(Document text c) -> (c, determine text nb intClasses documents)) devTestDocuments
|
2016-07-29 11:46:44 +00:00
|
|
|
|
2016-07-29 13:25:59 +00:00
|
|
|
let showResults (c, r) = putStrLn (classes !! c ++ " ~ " ++ classes !! r)
|
|
|
|
mapM_ showResults results
|
2016-07-29 11:46:44 +00:00
|
|
|
|
2016-07-30 12:22:34 +00:00
|
|
|
putStrLn $ "Recall: " ++ show (recall results)
|
|
|
|
putStrLn $ "Precision: " ++ show (precision results)
|
2016-07-29 17:39:30 +00:00
|
|
|
putStrLn $ "F Measure: " ++ show (fmeasure (precision results) (recall results))
|
2016-07-30 12:22:34 +00:00
|
|
|
putStrLn $ "Accuracy: " ++ show (accuracy results)
|