-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapriori_test.go
39 lines (30 loc) · 1.01 KB
/
apriori_test.go
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
32
33
34
35
36
37
38
39
package Apriori
import (
"testing"
)
func TestApriori(t *testing.T) {
apriori := NewApriori()
var err error
apriori.record, err = apriori.getRecord("simple.txt")
if err != nil {
t.Error(err)
return
}
cItemSet := apriori.findFirstCandidate() // 获取第一次的备选集
lItemSet := apriori.getSupportedItemSet(cItemSet) //获取备选集cItemset满足支持的集合
for !apriori.endTag {
ckItemset := apriori.getNextCandidate(lItemSet)
lkItemset := apriori.getSupportedItemSet(ckItemset)
apriori.getConfidencedItemset(lkItemset, lItemSet, apriori.dKCountMap, apriori.dCountMap) // 获取备选集cItemset满足置信度的集合
if len(apriori.confItemSet) != 0 { // 满足置信度的集合不为空
apriori.result(apriori.confItemSet) // 打印满足置信度的集合
}
apriori.confItemSet = apriori.confItemSet[:0]
cItemSet = ckItemset
lItemSet = lkItemset
apriori.dCountMap = make(map[int]int)
for k, v := range apriori.dKCountMap {
apriori.dCountMap[k] = v
}
}
}