From ce967324190bdb176b3eb4fec0c728ef134644e9 Mon Sep 17 00:00:00 2001 From: IGI-111 Date: Tue, 7 Apr 2015 14:54:45 +0000 Subject: [PATCH] corrected phase 2 --- DataModel.hs | 3 +++ phase1.hs | 2 +- phase2.hs | 9 +++++---- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/DataModel.hs b/DataModel.hs index 7ce2e48..fffeb07 100644 --- a/DataModel.hs +++ b/DataModel.hs @@ -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 diff --git a/phase1.hs b/phase1.hs index aa56fe7..192dee1 100644 --- a/phase1.hs +++ b/phase1.hs @@ -9,7 +9,7 @@ main :: IO() main = do args <- getArgs when (2 > length args) - (error "Usage: Main ") + (error "Usage: Main table.csv threshold [outfile.csv]") let filename = head args let threshold = read $ args !! 1 file <- readFile filename diff --git a/phase2.hs b/phase2.hs index c126122..5ea60c0 100644 --- a/phase2.hs +++ b/phase2.hs @@ -8,7 +8,7 @@ import Control.Monad(when) main :: IO() main = do args <- getArgs - when (3 /= length args) (error "Usage: phase2 ") + 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