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