corrected phase 2
This commit is contained in:
@@ -6,6 +6,7 @@ type Count = Int
|
||||
|
||||
type Frequency = Double
|
||||
type Confidence = Double
|
||||
type Lift = Double
|
||||
|
||||
class Freq a where
|
||||
frequency :: [ItemSet] -> a -> Frequency
|
||||
@@ -50,3 +51,5 @@ instance Freq Rule where
|
||||
confidence :: [ItemSet] -> Rule -> Confidence
|
||||
confidence table (Rule x y) = frequency table (Rule x y) / frequency table x
|
||||
|
||||
lift :: [ItemSet] -> Rule -> Lift
|
||||
lift table (Rule x y) = confidence table (Rule x y) / frequency table y
|
||||
|
||||
@@ -9,7 +9,7 @@ main :: IO()
|
||||
main = do
|
||||
args <- getArgs
|
||||
when (2 > length args)
|
||||
(error "Usage: Main <table.csv> <threshold> <outfile.csv>")
|
||||
(error "Usage: Main table.csv threshold [outfile.csv]")
|
||||
let filename = head args
|
||||
let threshold = read $ args !! 1
|
||||
file <- readFile filename
|
||||
|
||||
@@ -8,7 +8,7 @@ import Control.Monad(when)
|
||||
main :: IO()
|
||||
main = do
|
||||
args <- getArgs
|
||||
when (3 /= length args) (error "Usage: phase2 <table.csv> <frequents.csv> <threshold>")
|
||||
when (3 > length args) (error "Usage: phase2 table.csv frequents.csv threshold [out.assoc]")
|
||||
let threshold = read $ last args
|
||||
tableFile <- readFile $ head args
|
||||
freqFile <- readFile $ args !! 1
|
||||
@@ -18,9 +18,10 @@ main = do
|
||||
case parseCSV freqFile of
|
||||
Left _ -> error "Could not parse frequent patterns"
|
||||
Right freqFileContent -> do
|
||||
putStrLn output
|
||||
when (length args > 2) $
|
||||
writeFile (args !! 2) $ output
|
||||
--putStrLn output
|
||||
print $ zip rules (map (lift table) rules)
|
||||
when (length args > 3) $
|
||||
writeFile (args !! 3) $ output
|
||||
where
|
||||
freqPats = map (ItemSet. Set.fromList .map Item) (map tail freqFileContent)
|
||||
table = map (ItemSet. Set.fromList .map Item) tableFileContent
|
||||
|
||||
Reference in New Issue
Block a user