From 51d1cfc463e4f8507ae6d26368e64489ea69533d Mon Sep 17 00:00:00 2001 From: IGI-111 Date: Thu, 2 Apr 2015 08:38:59 +0200 Subject: [PATCH] modified to show frequency of frequent items --- apriori.hs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/apriori.hs b/apriori.hs index 869bfbf..6fb55d4 100644 --- a/apriori.hs +++ b/apriori.hs @@ -48,8 +48,8 @@ parseCSV :: String -> Either ParseError [ItemSet] parseCSV input = parse csvFile ("unknown") input -- frequent items -frequentItems :: [ItemSet] -> Support -> [(Item, Integer)] -frequentItems x y = Set.toList $ Map.keysSet pi frequency where +frequentItems :: Integral a => [ItemSet] -> Support -> Map Item a +frequentItems x y = pi where pi = Map.filter (>= frequency) m where frequency = ceiling(y * (fromIntegral $ length x)) where m = foldl count Map.empty x where @@ -65,12 +65,12 @@ main = do putStrLn "Apriori Algorithm for frequent itemsets mining" [f, s] <- getArgs c <- readFile f - case parse csvFile "(stdin)" c of + case parse csvFile "(stdin)" c of Left e -> do putStrLn "Error parsing input: " print e Right r -> do let i = frequentItems r (read s) - mapM_ print $ i + print $ i -- helper functions defined here