modified to show frequency of frequent items

This commit is contained in:
IGI-111
2015-04-02 08:38:59 +02:00
parent ffd45a82bc
commit 51d1cfc463

View File

@@ -48,8 +48,8 @@ parseCSV :: String -> Either ParseError [ItemSet]
parseCSV input = parse csvFile ("unknown") input parseCSV input = parse csvFile ("unknown") input
-- frequent items -- frequent items
frequentItems :: [ItemSet] -> Support -> [(Item, Integer)] frequentItems :: Integral a => [ItemSet] -> Support -> Map Item a
frequentItems x y = Set.toList $ Map.keysSet pi frequency where frequentItems x y = pi where
pi = Map.filter (>= frequency) m where pi = Map.filter (>= frequency) m where
frequency = ceiling(y * (fromIntegral $ length x)) where frequency = ceiling(y * (fromIntegral $ length x)) where
m = foldl count Map.empty x where m = foldl count Map.empty x where
@@ -65,12 +65,12 @@ main = do
putStrLn "Apriori Algorithm for frequent itemsets mining" putStrLn "Apriori Algorithm for frequent itemsets mining"
[f, s] <- getArgs [f, s] <- getArgs
c <- readFile f c <- readFile f
case parse csvFile "(stdin)" c of case parse csvFile "(stdin)" c of
Left e -> do putStrLn "Error parsing input: " Left e -> do putStrLn "Error parsing input: "
print e print e
Right r -> do Right r -> do
let i = frequentItems r (read s) let i = frequentItems r (read s)
mapM_ print $ i print $ i
-- helper functions defined here -- helper functions defined here