-
Notifications
You must be signed in to change notification settings - Fork 3
/
example.js
31 lines (26 loc) · 1016 Bytes
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
var apriori = require("../dist/apriori");
var transactions = [
[1, 3, 4],
[2, 3, 5],
[1, 2, 3, 5],
[2, 5],
[1, 2, 3, 5]
];
// Execute Apriori with a minimum support of 40%.
var apriori = new apriori.Apriori(.4);
console.log(`Executing Apriori...`);
// Returns itemsets 'as soon as possible' through events.
apriori.on('data', function (itemset) {
// Do something with the frequent itemset.
var support = itemset.support;
var items = itemset.items;
console.log(`Itemset { ${items.join(',')} } is frequent and have a support of ${support}`);
});
// Execute Apriori on a given set of transactions.
apriori.exec(transactions)
.then(function (result) {
// Returns both the collection of frequent itemsets and execution time in millisecond.
var frequentItemsets = result.itemsets;
var executionTime = result.executionTime;
console.log(`Finished executing Apriori. ${frequentItemsets.length} frequent itemsets were found in ${executionTime}ms.`);
});